public void UpdateAdditiveAnimation(SteamVR_Action_Skeleton skeletonAction, SteamVR_Input_Sources inputSource)
            {
                if (skeletonAction.GetSkeletalTrackingLevel() == EVRSkeletalTrackingLevel.VRSkeletalTracking_Estimated)
                {
                    //do not apply additive animation on low fidelity controllers, eg. Vive Wands and Touch
                    return;
                }

                SteamVR_Skeleton_PoseSnapshot snapshot = GetHandSnapshot(inputSource);
                SteamVR_Skeleton_Pose_Hand    poseHand = pose.GetHand(inputSource);

                for (int boneIndex = 0; boneIndex < snapshotL.bonePositions.Length; boneIndex++)
                {
                    int fingerIndex = SteamVR_Skeleton_JointIndexes.GetFingerForBone(boneIndex);
                    SteamVR_Skeleton_FingerExtensionTypes extensionType = poseHand.GetMovementTypeForBone(boneIndex);

                    if (extensionType == SteamVR_Skeleton_FingerExtensionTypes.Free)
                    {
                        snapshot.bonePositions[boneIndex] = skeletonAction.bonePositions[boneIndex];
                        snapshot.boneRotations[boneIndex] = skeletonAction.boneRotations[boneIndex];
                    }
                    if (extensionType == SteamVR_Skeleton_FingerExtensionTypes.Extend)
                    {
                        // lerp to open pose by fingercurl
                        snapshot.bonePositions[boneIndex] = Vector3.Lerp(poseHand.bonePositions[boneIndex], skeletonAction.bonePositions[boneIndex], 1 - skeletonAction.fingerCurls[fingerIndex]);
                        snapshot.boneRotations[boneIndex] = Quaternion.Lerp(poseHand.boneRotations[boneIndex], skeletonAction.boneRotations[boneIndex], 1 - skeletonAction.fingerCurls[fingerIndex]);
                    }
                    if (extensionType == SteamVR_Skeleton_FingerExtensionTypes.Contract)
                    {
                        // lerp to closed pose by fingercurl
                        snapshot.bonePositions[boneIndex] = Vector3.Lerp(poseHand.bonePositions[boneIndex], skeletonAction.bonePositions[boneIndex], skeletonAction.fingerCurls[fingerIndex]);
                        snapshot.boneRotations[boneIndex] = Quaternion.Lerp(poseHand.boneRotations[boneIndex], skeletonAction.boneRotations[boneIndex], skeletonAction.fingerCurls[fingerIndex]);
                    }
                }
            }
示例#2
0
            public void UpdateAdditiveAnimation(SteamVR_Action_Skeleton skeletonAction, SteamVR_Input_Sources inputSource)
            {
                SteamVR_Skeleton_PoseSnapshot snapshot = GetHandSnapshot(inputSource);
                SteamVR_Skeleton_Pose_Hand    poseHand = pose.GetHand(inputSource);

                for (int boneIndex = 0; boneIndex < snapshotL.bonePositions.Length; boneIndex++)
                {
                    int fingerIndex = SteamVR_Skeleton_JointIndexes.GetFingerForBone(boneIndex);
                    SteamVR_Skeleton_FingerExtensionTypes extensionType = poseHand.GetMovementTypeForBone(boneIndex);

                    if (extensionType == SteamVR_Skeleton_FingerExtensionTypes.Free)
                    {
                        snapshot.bonePositions[boneIndex] = skeletonAction.bonePositions[boneIndex];
                        snapshot.boneRotations[boneIndex] = skeletonAction.boneRotations[boneIndex];
                    }
                    if (extensionType == SteamVR_Skeleton_FingerExtensionTypes.Extend)
                    {
                        // lerp to open pose by fingercurl
                        snapshot.bonePositions[boneIndex] = Vector3.Lerp(poseHand.bonePositions[boneIndex], skeletonAction.bonePositions[boneIndex], 1 - skeletonAction.fingerCurls[fingerIndex]);
                        snapshot.boneRotations[boneIndex] = Quaternion.Lerp(poseHand.boneRotations[boneIndex], skeletonAction.boneRotations[boneIndex], 1 - skeletonAction.fingerCurls[fingerIndex]);
                    }
                    if (extensionType == SteamVR_Skeleton_FingerExtensionTypes.Contract)
                    {
                        // lerp to closed pose by fingercurl
                        snapshot.bonePositions[boneIndex] = Vector3.Lerp(poseHand.bonePositions[boneIndex], skeletonAction.bonePositions[boneIndex], skeletonAction.fingerCurls[fingerIndex]);
                        snapshot.boneRotations[boneIndex] = Quaternion.Lerp(poseHand.boneRotations[boneIndex], skeletonAction.boneRotations[boneIndex], skeletonAction.fingerCurls[fingerIndex]);
                    }
                }
            }
            public void UpdateAdditiveAnimation(SteamVR_Action_Skeleton skeletonAction, SteamVR_Input_Sources inputSource)
            {
                SteamVR_Skeleton_PoseSnapshot snapshot = GetHandSnapshot(inputSource);
                SteamVR_Skeleton_Pose_Hand    poseHand = pose.GetHand(inputSource);

                //setup mirrored pose buffers
                if (additivePositionBuffer == null)
                {
                    additivePositionBuffer = new Vector3[skeletonAction.boneCount];
                }
                if (additiveRotationBuffer == null)
                {
                    additiveRotationBuffer = new Quaternion[skeletonAction.boneCount];
                }


                for (int boneIndex = 0; boneIndex < snapshotL.bonePositions.Length; boneIndex++)
                {
                    int fingerIndex = SteamVR_Skeleton_JointIndexes.GetFingerForBone(boneIndex);
                    SteamVR_Skeleton_FingerExtensionTypes extensionType = poseHand.GetMovementTypeForBone(boneIndex);

                    //do target pose mirroring on left hand
                    if (inputSource == SteamVR_Input_Sources.LeftHand)
                    {
                        SteamVR_Behaviour_Skeleton.MirrorBonePosition(ref skeletonAction.bonePositions[boneIndex], ref additivePositionBuffer[boneIndex], boneIndex);
                        SteamVR_Behaviour_Skeleton.MirrorBoneRotation(ref skeletonAction.boneRotations[boneIndex], ref additiveRotationBuffer[boneIndex], boneIndex);
                    }
                    else
                    {
                        additivePositionBuffer[boneIndex] = skeletonAction.bonePositions[boneIndex];
                        additiveRotationBuffer[boneIndex] = skeletonAction.boneRotations[boneIndex];
                    }



                    if (extensionType == SteamVR_Skeleton_FingerExtensionTypes.Free)
                    {
                        snapshot.bonePositions[boneIndex] = additivePositionBuffer[boneIndex];
                        snapshot.boneRotations[boneIndex] = additiveRotationBuffer[boneIndex];
                    }
                    else if (extensionType == SteamVR_Skeleton_FingerExtensionTypes.Extend)
                    {
                        // lerp to open pose by fingercurl
                        snapshot.bonePositions[boneIndex] = Vector3.Lerp(poseHand.bonePositions[boneIndex], additivePositionBuffer[boneIndex], 1 - skeletonAction.fingerCurls[fingerIndex]);
                        snapshot.boneRotations[boneIndex] = Quaternion.Lerp(poseHand.boneRotations[boneIndex], additiveRotationBuffer[boneIndex], 1 - skeletonAction.fingerCurls[fingerIndex]);
                    }
                    else if (extensionType == SteamVR_Skeleton_FingerExtensionTypes.Contract)
                    {
                        // lerp to closed pose by fingercurl
                        snapshot.bonePositions[boneIndex] = Vector3.Lerp(poseHand.bonePositions[boneIndex], additivePositionBuffer[boneIndex], skeletonAction.fingerCurls[fingerIndex]);
                        snapshot.boneRotations[boneIndex] = Quaternion.Lerp(poseHand.boneRotations[boneIndex], additiveRotationBuffer[boneIndex], skeletonAction.fingerCurls[fingerIndex]);
                    }
                }
            }
 private static void PopulatePoseData(ref SteamVR_Skeleton_Pose_Hand p, PoseDat d)
 {
     p.thumbFingerMovementType  = d.thumbFingerMovementType;
     p.indexFingerMovementType  = d.indexFingerMovementType;
     p.middleFingerMovementType = d.middleFingerMovementType;
     p.ringFingerMovementType   = d.ringFingerMovementType;
     p.ignoreRootPoseData       = d.ignoreRootPoseData;
     p.ignoreWristPoseData      = d.ignoreWristPoseData;
     p.position      = d.position;
     p.rotation      = d.rotation;
     p.bonePositions = d.bonePositions;
     p.boneRotations = d.boneRotations;
 }
        public static void Initialize_SteamVR_Skeleton_Pose_Hand(ref SteamVR_Skeleton_Pose_Hand p, int index, string hand)
        {
            Debug.Log("Initialize_SteamVR_Skeleton_Pose_Hand - PoseIndex: " + index + " Hand: " + hand);
            string poseName = poseIndexToName[index];
            string poseKey  = poseName + ":" + hand;

            if (poseToData.ContainsKey(poseKey))
            {
                Debug.Log("Have Pose Data, populating SteamVR_Skeleton_Pose_Hand");
                PoseDat d = poseToData[poseKey];
                PopulatePoseData(ref p, d);
            }
            else
            {
                Debug.LogError("Did not have pose data for pose index: " + index + " and hand: " + hand);
            }
        }
        protected void SaveHandData(SteamVR_Skeleton_Pose_Hand handData, SteamVR_Behaviour_Skeleton thisSkeleton)
        {
            handData.position = thisSkeleton.transform.InverseTransformPoint(poser.transform.position);
            //handData.position = thisSkeleton.transform.localPosition;
            handData.rotation = Quaternion.Inverse(thisSkeleton.transform.localRotation);

            handData.bonePositions = new Vector3[SteamVR_Action_Skeleton.numBones];
            handData.boneRotations = new Quaternion[SteamVR_Action_Skeleton.numBones];

            for (int boneIndex = 0; boneIndex < SteamVR_Action_Skeleton.numBones; boneIndex++)
            {
                Transform bone = thisSkeleton.GetBone(boneIndex);
                handData.bonePositions[boneIndex] = bone.localPosition;
                handData.boneRotations[boneIndex] = bone.localRotation;
            }

            EditorUtility.SetDirty(activePose);
        }
示例#7
0
        public virtual void UpdateSkeletonTransforms()
        {
            Vector3[]    bonePositions = GetBonePositions();
            Quaternion[] boneRotations = GetBoneRotations();

            if (skeletonBlend <= 0)
            {
                if (blendPoser != null)
                {
                    SteamVR_Skeleton_Pose_Hand mainPose = blendPoser.skeletonMainPose.GetHand(inputSource);
                    for (int boneIndex = 0; boneIndex < bones.Length; boneIndex++)
                    {
                        if (bones[boneIndex] == null)
                        {
                            continue;
                        }

                        if ((boneIndex == SteamVR_Skeleton_JointIndexes.wrist && mainPose.ignoreWristPoseData) ||
                            (boneIndex == SteamVR_Skeleton_JointIndexes.root && mainPose.ignoreRootPoseData))
                        {
                            SetBonePosition(boneIndex, bonePositions[boneIndex]);
                            SetBoneRotation(boneIndex, boneRotations[boneIndex]);
                        }
                        else
                        {
                            Quaternion poseRotation = GetBlendPoseForBone(boneIndex, boneRotations[boneIndex]);

                            SetBonePosition(boneIndex, blendSnapshot.bonePositions[boneIndex]);
                            SetBoneRotation(boneIndex, poseRotation);
                        }
                    }
                }
                else
                {
                    for (int boneIndex = 0; boneIndex < bones.Length; boneIndex++)
                    {
                        Quaternion poseRotation = GetBlendPoseForBone(boneIndex, boneRotations[boneIndex]);

                        SetBonePosition(boneIndex, blendSnapshot.bonePositions[boneIndex]);
                        SetBoneRotation(boneIndex, poseRotation);
                    }
                }
            }
            else if (skeletonBlend >= 1)
            {
                for (int boneIndex = 0; boneIndex < bones.Length; boneIndex++)
                {
                    if (bones[boneIndex] == null)
                    {
                        continue;
                    }

                    SetBonePosition(boneIndex, bonePositions[boneIndex]);
                    SetBoneRotation(boneIndex, boneRotations[boneIndex]);
                }
            }
            else
            {
                for (int boneIndex = 0; boneIndex < bones.Length; boneIndex++)
                {
                    if (bones[boneIndex] == null)
                    {
                        continue;
                    }

                    if (blendPoser != null)
                    {
                        SteamVR_Skeleton_Pose_Hand mainPose = blendPoser.skeletonMainPose.GetHand(inputSource);

                        if ((boneIndex == SteamVR_Skeleton_JointIndexes.wrist && mainPose.ignoreWristPoseData) ||
                            (boneIndex == SteamVR_Skeleton_JointIndexes.root && mainPose.ignoreRootPoseData))
                        {
                            SetBonePosition(boneIndex, bonePositions[boneIndex]);
                            SetBoneRotation(boneIndex, boneRotations[boneIndex]);
                        }
                        else
                        {
                            //Quaternion poseRotation = GetBlendPoseForBone(boneIndex, boneRotations[boneIndex]);

                            SetBonePosition(boneIndex, Vector3.Lerp(blendSnapshot.bonePositions[boneIndex], bonePositions[boneIndex], skeletonBlend));
                            SetBoneRotation(boneIndex, Quaternion.Lerp(blendSnapshot.boneRotations[boneIndex], boneRotations[boneIndex], skeletonBlend));
                            //SetBoneRotation(boneIndex, GetBlendPoseForBone(boneIndex, boneRotations[boneIndex]));
                        }
                    }
                    else
                    {
                        if (blendSnapshot == null)
                        {
                            SetBonePosition(boneIndex, Vector3.Lerp(bones[boneIndex].localPosition, bonePositions[boneIndex], skeletonBlend));
                            SetBoneRotation(boneIndex, Quaternion.Lerp(bones[boneIndex].localRotation, boneRotations[boneIndex], skeletonBlend));
                        }
                        else
                        {
                            SetBonePosition(boneIndex, Vector3.Lerp(blendSnapshot.bonePositions[boneIndex], bonePositions[boneIndex], skeletonBlend));
                            SetBoneRotation(boneIndex, Quaternion.Lerp(blendSnapshot.boneRotations[boneIndex], boneRotations[boneIndex], skeletonBlend));
                        }
                    }
                }
            }


            if (onBoneTransformsUpdated != null)
            {
                onBoneTransformsUpdated.Invoke(this, inputSource);
            }
            if (onBoneTransformsUpdatedEvent != null)
            {
                onBoneTransformsUpdatedEvent.Invoke(this, inputSource);
            }
        }
        protected void UpdatePreviewHand(SerializedProperty instanceProperty, SerializedProperty showPreviewProperty, GameObject previewPrefab, SteamVR_Skeleton_Pose_Hand handData, SteamVR_Skeleton_Pose sourcePose, bool forceUpdate)
        {
            GameObject preview = instanceProperty.objectReferenceValue as GameObject;

            //EditorGUILayout.PropertyField(showPreviewProperty);

            if (showPreviewProperty.boolValue)
            {
                if (forceUpdate && preview != null)
                {
                    DestroyImmediate(preview);
                }

                if (preview == null)
                {
                    preview = Instantiate <GameObject>(previewPrefab);
                    preview.transform.localScale    = Vector3.one * poserScale.floatValue;
                    preview.transform.parent        = poser.transform;
                    preview.transform.localPosition = Vector3.zero;
                    preview.transform.localRotation = Quaternion.identity;

                    SteamVR_Behaviour_Skeleton previewSkeleton = null;

                    if (preview != null)
                    {
                        previewSkeleton = preview.GetComponent <SteamVR_Behaviour_Skeleton>();
                    }

                    if (previewSkeleton != null)
                    {
                        if (handData.bonePositions == null || handData.bonePositions.Length == 0)
                        {
                            SteamVR_Skeleton_Pose poseResource = (SteamVR_Skeleton_Pose)Resources.Load("ReferencePose_OpenHand");
                            DeepCopyPose(poseResource, sourcePose);
                            EditorUtility.SetDirty(sourcePose);
                        }

                        preview.transform.localPosition = Vector3.zero;
                        preview.transform.localRotation = Quaternion.identity;
                        preview.transform.parent        = null;
                        preview.transform.localScale    = Vector3.one * poserScale.floatValue;
                        preview.transform.parent        = poser.transform;

                        preview.transform.localRotation = Quaternion.Inverse(handData.rotation);
                        preview.transform.position      = preview.transform.TransformPoint(-handData.position);


                        for (int boneIndex = 0; boneIndex < handData.bonePositions.Length; boneIndex++)
                        {
                            Transform bone = previewSkeleton.GetBone(boneIndex);
                            bone.localPosition = handData.bonePositions[boneIndex];
                            bone.localRotation = handData.boneRotations[boneIndex];
                        }
                    }
                    SceneView.RepaintAll();
                    instanceProperty.objectReferenceValue = preview;
                }
            }
            else
            {
                if (preview != null)
                {
                    DestroyImmediate(preview);
                    SceneView.RepaintAll();
                }
            }
        }
        protected void DrawHand(bool showHand, SteamVR_Skeleton_Pose_Hand handData, SteamVR_Skeleton_Pose_Hand otherData, bool getFromOpposite, SerializedProperty showPreviewProperty)
        {
            SteamVR_Behaviour_Skeleton thisSkeleton;
            SteamVR_Behaviour_Skeleton oppositeSkeleton;
            string thisSourceString;
            string oppositeSourceString;

            if (handData.inputSource == SteamVR_Input_Sources.LeftHand)
            {
                thisSkeleton         = leftSkeleton;
                thisSourceString     = "Left Hand";
                oppositeSourceString = "Right Hand";
                oppositeSkeleton     = rightSkeleton;
            }
            else
            {
                thisSkeleton         = rightSkeleton;
                thisSourceString     = "Right Hand";
                oppositeSourceString = "Left Hand";
                oppositeSkeleton     = leftSkeleton;
            }


            if (showHand)
            {
                if (getFromOpposite)
                {
                    bool confirm = EditorUtility.DisplayDialog("SteamVR", string.Format("This will overwrite your current {0} skeleton data. (with data from the {1} skeleton)", thisSourceString, oppositeSourceString), "Overwrite", "Cancel");
                    if (confirm)
                    {
                        Vector3 reflectedPosition = new Vector3(-oppositeSkeleton.transform.localPosition.x, oppositeSkeleton.transform.localPosition.y, oppositeSkeleton.transform.localPosition.z);
                        thisSkeleton.transform.localPosition = reflectedPosition;

                        Quaternion oppositeRotation  = oppositeSkeleton.transform.localRotation;
                        Quaternion reflectedRotation = new Quaternion(-oppositeRotation.x, oppositeRotation.y, oppositeRotation.z, -oppositeRotation.w);
                        thisSkeleton.transform.localRotation = reflectedRotation;


                        for (int boneIndex = 0; boneIndex < SteamVR_Action_Skeleton.numBones; boneIndex++)
                        {
                            Transform boneThis     = thisSkeleton.GetBone(boneIndex);
                            Transform boneOpposite = oppositeSkeleton.GetBone(boneIndex);

                            boneThis.localPosition = boneOpposite.localPosition;
                            boneThis.localRotation = boneOpposite.localRotation;
                        }

                        handData.thumbFingerMovementType  = otherData.thumbFingerMovementType;
                        handData.indexFingerMovementType  = otherData.indexFingerMovementType;
                        handData.middleFingerMovementType = otherData.middleFingerMovementType;
                        handData.ringFingerMovementType   = otherData.ringFingerMovementType;
                        handData.pinkyFingerMovementType  = otherData.pinkyFingerMovementType;

                        EditorUtility.SetDirty(poser.skeletonMainPose);
                    }
                }
            }

            EditorGUIUtility.labelWidth = 120;
            SteamVR_Skeleton_FingerExtensionTypes newThumb  = (SteamVR_Skeleton_FingerExtensionTypes)EditorGUILayout.EnumPopup("Thumb movement", handData.thumbFingerMovementType);
            SteamVR_Skeleton_FingerExtensionTypes newIndex  = (SteamVR_Skeleton_FingerExtensionTypes)EditorGUILayout.EnumPopup("Index movement", handData.indexFingerMovementType);
            SteamVR_Skeleton_FingerExtensionTypes newMiddle = (SteamVR_Skeleton_FingerExtensionTypes)EditorGUILayout.EnumPopup("Middle movement", handData.middleFingerMovementType);
            SteamVR_Skeleton_FingerExtensionTypes newRing   = (SteamVR_Skeleton_FingerExtensionTypes)EditorGUILayout.EnumPopup("Ring movement", handData.ringFingerMovementType);
            SteamVR_Skeleton_FingerExtensionTypes newPinky  = (SteamVR_Skeleton_FingerExtensionTypes)EditorGUILayout.EnumPopup("Pinky movement", handData.pinkyFingerMovementType);

            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(showPreviewProperty);
            EditorGUIUtility.labelWidth = 0;

            if (newThumb != handData.thumbFingerMovementType || newIndex != handData.indexFingerMovementType ||
                newMiddle != handData.middleFingerMovementType || newRing != handData.ringFingerMovementType ||
                newPinky != handData.pinkyFingerMovementType)
            {
                handData.thumbFingerMovementType  = newThumb;
                handData.indexFingerMovementType  = newIndex;
                handData.middleFingerMovementType = newMiddle;
                handData.ringFingerMovementType   = newRing;
                handData.pinkyFingerMovementType  = newPinky;

                EditorUtility.SetDirty(poser.skeletonMainPose);
            }
        }
示例#10
0
        protected void UpdatePreviewHand(SerializedProperty instanceProperty, SerializedProperty showPreviewProperty, SerializedProperty prefabProperty, SteamVR_Skeleton_Pose_Hand handData)
        {
            GameObject preview = instanceProperty.objectReferenceValue as GameObject;

            EditorGUILayout.PropertyField(showPreviewProperty);
            if (showPreviewProperty.boolValue)
            {
                if (preview == null)
                {
                    preview = GameObject.Instantiate <GameObject>((GameObject)prefabProperty.objectReferenceValue);
                    preview.transform.parent        = poser.transform;
                    preview.transform.localPosition = Vector3.zero;
                    preview.transform.localRotation = Quaternion.identity;

                    SteamVR_Behaviour_Skeleton previewSkeleton = null;

                    if (preview != null)
                    {
                        previewSkeleton = preview.GetComponent <SteamVR_Behaviour_Skeleton>();
                    }

                    if (previewSkeleton != null)
                    {
                        if (handData.bonePositions == null || handData.bonePositions.Length == 0)
                        {
                            previewSkeleton.ForceToReferencePose(defaultReferencePose);
                            SaveHandData(handData, previewSkeleton);
                        }

                        preview.transform.localPosition = Vector3.zero;
                        preview.transform.localRotation = Quaternion.identity;

                        preview.transform.localRotation = Quaternion.Inverse(handData.rotation);
                        preview.transform.position      = preview.transform.TransformPoint(-handData.position);

                        for (int boneIndex = 0; boneIndex < handData.bonePositions.Length; boneIndex++)
                        {
                            Transform bone = previewSkeleton.GetBone(boneIndex);
                            bone.localPosition = handData.bonePositions[boneIndex];
                            bone.localRotation = handData.boneRotations[boneIndex];
                        }
                    }

                    instanceProperty.objectReferenceValue = preview;
                }
            }
            else
            {
                if (preview != null)
                {
                    DestroyImmediate(preview);
                }
            }
        }
示例#11
0
        protected void DrawHand(bool showHand, SteamVR_Skeleton_Pose_Hand handData, SteamVR_Behaviour_Skeleton leftSkeleton, SteamVR_Behaviour_Skeleton rightSkeleton)
        {
            SteamVR_Behaviour_Skeleton thisSkeleton;
            SteamVR_Behaviour_Skeleton oppositeSkeleton;
            string thisSourceString;
            string oppositeSourceString;

            if (handData.inputSource == SteamVR_Input_Sources.LeftHand)
            {
                thisSkeleton         = leftSkeleton;
                thisSourceString     = "Left Hand";
                oppositeSourceString = "Right Hand";
                oppositeSkeleton     = rightSkeleton;
            }
            else
            {
                thisSkeleton         = rightSkeleton;
                thisSourceString     = "Right Hand";
                oppositeSourceString = "Left Hand";
                oppositeSkeleton     = leftSkeleton;
            }


            if (showHand)
            {
                bool save = GUILayout.Button(string.Format("Save {0}", thisSourceString));
                if (save)
                {
                    SaveHandData(handData, thisSkeleton);
                }

                bool getFromOpposite = GUILayout.Button(string.Format("Mirror {0} pose onto {1} skeleton", oppositeSourceString, thisSourceString));
                if (getFromOpposite)
                {
                    bool confirm = EditorUtility.DisplayDialog("SteamVR", string.Format("This will overwrite your current {0} skeleton data. (with data from the {1} skeleton)", thisSourceString, oppositeSourceString), "Overwrite", "Cancel");
                    if (confirm)
                    {
                        Vector3 reflectedPosition = new Vector3(-oppositeSkeleton.transform.localPosition.x, oppositeSkeleton.transform.localPosition.y, oppositeSkeleton.transform.localPosition.z);
                        thisSkeleton.transform.localPosition = reflectedPosition;

                        Quaternion oppositeRotation  = oppositeSkeleton.transform.localRotation;
                        Quaternion reflectedRotation = new Quaternion(-oppositeRotation.x, oppositeRotation.y, oppositeRotation.z, -oppositeRotation.w);
                        thisSkeleton.transform.localRotation = reflectedRotation;

                        handData.position = reflectedPosition;
                        handData.rotation = reflectedRotation;

                        handData.bonePositions = new Vector3[SteamVR_Action_Skeleton.numBones];
                        handData.boneRotations = new Quaternion[SteamVR_Action_Skeleton.numBones];

                        for (int boneIndex = 0; boneIndex < SteamVR_Action_Skeleton.numBones; boneIndex++)
                        {
                            Transform boneThis     = thisSkeleton.GetBone(boneIndex);
                            Transform boneOpposite = oppositeSkeleton.GetBone(boneIndex);

                            boneThis.localPosition = boneOpposite.localPosition;
                            boneThis.localRotation = boneOpposite.localRotation;

                            handData.bonePositions[boneIndex] = boneThis.localPosition;
                            handData.boneRotations[boneIndex] = boneThis.localRotation;
                        }

                        EditorUtility.SetDirty(poser.skeletonPose);
                    }
                }

                GUILayout.BeginHorizontal();
                GUILayout.Label("Force to reference pose");
                GUILayout.FlexibleSpace();

                forceToReferencePose = (EVRSkeletalReferencePose)EditorGUILayout.EnumPopup(forceToReferencePose);

                GUILayout.FlexibleSpace();
                bool forcePose = GUILayout.Button("set");
                GUILayout.EndHorizontal();
                if (forcePose)
                {
                    bool confirm = EditorUtility.DisplayDialog("SteamVR", string.Format("This will overwrite your current {0} skeleton data. (with data from the {1} reference pose)", thisSourceString, forceToReferencePose.ToString()), "Overwrite", "Cancel");
                    if (confirm)
                    {
                        thisSkeleton.ForceToReferencePose(forceToReferencePose);
                    }
                }

                SteamVR_Skeleton_FingerExtensionTypes newThumb  = (SteamVR_Skeleton_FingerExtensionTypes)EditorGUILayout.EnumPopup("Thumb movement", handData.thumbFingerMovementType);
                SteamVR_Skeleton_FingerExtensionTypes newIndex  = (SteamVR_Skeleton_FingerExtensionTypes)EditorGUILayout.EnumPopup("Index movement", handData.indexFingerMovementType);
                SteamVR_Skeleton_FingerExtensionTypes newMiddle = (SteamVR_Skeleton_FingerExtensionTypes)EditorGUILayout.EnumPopup("Middle movement", handData.middleFingerMovementType);
                SteamVR_Skeleton_FingerExtensionTypes newRing   = (SteamVR_Skeleton_FingerExtensionTypes)EditorGUILayout.EnumPopup("Ring movement", handData.ringFingerMovementType);
                SteamVR_Skeleton_FingerExtensionTypes newPinky  = (SteamVR_Skeleton_FingerExtensionTypes)EditorGUILayout.EnumPopup("Pinky movement", handData.pinkyFingerMovementType);

                if (newThumb != handData.thumbFingerMovementType || newIndex != handData.indexFingerMovementType ||
                    newMiddle != handData.middleFingerMovementType || newRing != handData.ringFingerMovementType ||
                    newPinky != handData.pinkyFingerMovementType)
                {
                    if ((int)newThumb >= 2 || (int)newIndex >= 2 || (int)newMiddle >= 2 || (int)newRing >= 2 || (int)newPinky >= 2)
                    {
                        Debug.LogError("<b>[SteamVR Input]</b> Unfortunately only Static and Free modes are supported in this beta.");
                        return;
                    }

                    handData.thumbFingerMovementType  = newThumb;
                    handData.indexFingerMovementType  = newIndex;
                    handData.middleFingerMovementType = newMiddle;
                    handData.ringFingerMovementType   = newRing;
                    handData.pinkyFingerMovementType  = newPinky;

                    EditorUtility.SetDirty(poser.skeletonPose);
                }
            }
        }
示例#12
0
 /// <summary>
 /// Blend from the current skeletonBlend amount to pose animation. (skeletonBlend = 0)
 /// Note: This will ignore the root position and rotation of the pose.
 /// </summary>
 /// <param name="overTime">How long you want the blend to take (in seconds)</param>
 /// <param name="attachToTransform">If you have a positiona and rotation offset for your pose you can attach it to a particular transform</param>
 public void BlendToPose(SteamVR_Skeleton_Pose pose, Transform attachToTransform, float overTime = 0.1f)
 {
     blendToPose = pose.GetHand(inputSource);
     BlendTo(0, overTime);
 }