IEnumerator TestAnimations()
        {
            SimpleUI.UIManager.ShowGameMessage("testing animations");
            yield return(new WaitForSeconds(3));

            for (int i = 0; i < 4; i++)
            {
                SimpleUI.UIManager.ShowGameMessage("testing animation : " + i.ToString());
                getWorkingHand.GetComponentInChildren <Animator>().SetInteger("AnimationState", i);
                getWorkingHand.BlendToAnimation(.25f);
                yield return(new WaitForSeconds(1));

                SimpleUI.UIManager.ShowGameMessage("Baking...");
                yield return(new WaitForSeconds(1));

                string fileName = "_ANIMPOSE_" + i + "_" + this.fileName + ".asset";
                SteamVR_Skeleton_Pose newPose = MakeNewPose(fileName, null);
                SaveHandData(newPose.GetHand(baker.handToUse), getWorkingHand);
                CopyHand(newPose, newPose.GetHand(baker.handToUse), newPose.GetHand(getOppositeHand.inputSource));

                yield return(new WaitForSeconds(3));

                SimpleUI.UIManager.ShowGameMessage("blendign bakc from : " + i.ToString());

                getWorkingHand.BlendToSkeleton(.25f);

                yield return(new WaitForSeconds(2));
            }



            SimpleUI.UIManager.ShowGameMessage("Done With ROUTINE!");
        }
        void CopyHand(SteamVR_Skeleton_Pose pose, SteamVR_Skeleton_Pose_Hand source, SteamVR_Skeleton_Pose_Hand dest)
        {
            int boneNum = SteamVR_Action_Skeleton.numBones;

            if (dest.bonePositions == null)
            {
                dest.bonePositions = new Vector3[boneNum];
            }
            if (dest.boneRotations == null)
            {
                dest.boneRotations = new Quaternion[boneNum];
            }


            dest.position = new Vector3(-source.position.x, source.position.y, source.position.z);
            dest.rotation = new Quaternion(-source.rotation.x, source.rotation.y, source.rotation.z, -source.rotation.w);

            for (int boneIndex = 0; boneIndex < SteamVR_Action_Skeleton.numBones; boneIndex++)
            {
                dest.bonePositions[boneIndex] = source.bonePositions[boneIndex];
                dest.boneRotations[boneIndex] = source.boneRotations[boneIndex];
                // EditorUtility.DisplayProgressBar("Copying...", "Copying right hand pose", (float)boneIndex / (float)boneNum / 2f);
            }


            dest.thumbFingerMovementType  = source.thumbFingerMovementType;
            dest.indexFingerMovementType  = source.indexFingerMovementType;
            dest.middleFingerMovementType = source.middleFingerMovementType;
            dest.ringFingerMovementType   = source.ringFingerMovementType;
            dest.pinkyFingerMovementType  = source.pinkyFingerMovementType;

            //set ours dirty

            EditorUtility.SetDirty(pose);
        }
Example #3
0
            /// <summary>
            /// Init based on an existing Skeleton_Pose
            /// </summary>
            public SkeletonBlendablePose(SteamVR_Skeleton_Pose p)
            {
                pose      = p;
                snapshotR = new SteamVR_Skeleton_PoseSnapshot(p.rightHand.bonePositions.Length, HandType.RightHand);
                snapshotL = new SteamVR_Skeleton_PoseSnapshot(p.leftHand.bonePositions.Length, HandType.LeftHand);

                PoseToSnapshots();
            }
        void CreateBlendingBehaviorsFromAllPoses()
        {
            int count = allPosesProperty.arraySize;

            for (int i = 0; i < count; i++)
            {
                SerializedProperty    p        = allPosesProperty.GetArrayElementAtIndex(i);
                SteamVR_Skeleton_Pose behavior = (SteamVR_Skeleton_Pose)p.objectReferenceValue;

                int c = blendingBehaviourArray.arraySize;
                blendingBehaviourArray.InsertArrayElementAtIndex(c);
                blendingBehaviourArray.GetArrayElementAtIndex(c).FindPropertyRelative("name").stringValue    = behavior.name;
                blendingBehaviourArray.GetArrayElementAtIndex(c).FindPropertyRelative("pose").intValue       = i;//+1;
                blendingBehaviourArray.GetArrayElementAtIndex(c).FindPropertyRelative("type").enumValueIndex = 0;
                serializedObject.ApplyModifiedProperties();
                EditorUtility.SetDirty(poserBehavior);
            }
        }
        SteamVR_Skeleton_Pose OpenHand;// =  (SteamVR_Skeleton_Pose)Resources.Load("ReferencePose_OpenHand");


        SteamVR_Skeleton_Pose MakeNewPose(string fileName, SteamVR_Skeleton_Pose template)
        {
            SteamVR_Skeleton_Pose newPose = ScriptableObject.CreateInstance <SteamVR_Skeleton_Pose>();

            SteamVR_Skeleton_Pose poseResource = template;

            if (poseResource == null)
            {
                poseResource = OpenHand;                      //(SteamVR_Skeleton_Pose)Resources.Load("ReferencePose_OpenHand");
            }
            DeepCopyPose(poseResource, newPose);
            AssetDatabase.CreateAsset(newPose, "Assets/" + fileName);

            AssetDatabase.SaveAssets();


            EditorUtility.SetDirty(newPose);
            return(newPose);
        }
Example #6
0
        void CopyPoseSelect()
        {
            string selected = EditorUtility.OpenFilePanel("Open Skeleton Pose ScriptableObject", Application.dataPath, "asset");

            selected = selected.Replace(Application.dataPath, "Assets");

            if (selected == null)
            {
                return;
            }

            SteamVR_Skeleton_Pose newPose = (SteamVR_Skeleton_Pose)AssetDatabase.LoadAssetAtPath(selected, typeof(SteamVR_Skeleton_Pose));

            if (newPose == null)
            {
                EditorUtility.DisplayDialog("WARNING", "Asset could not be loaded. Is it not a SteamVR_Skeleton_Pose?", "ok");
                return;
            }
            DeepCopyPose(newPose, activePose);
        }
Example #7
0
        public AssetLoader()
        {
            EmptyTexture = new Texture2D(1, 1);
            EmptyTexture.SetPixel(0, 0, Color.clear);
            EmptyTexture.Apply();

            var postCreditsBundle = LoadBundle("cinema-camera");

            PostCreditsPrefab        = LoadAsset <GameObject>(postCreditsBundle, "postcreditscamera.prefab");
            PostCreditsRenderTexture = LoadAsset <RenderTexture>(postCreditsBundle, "screen.renderTexture");

            var skeletalHandsBundle = LoadBundle("skeletal-hands");

            HandPrefab = LoadAsset <GameObject>(skeletalHandsBundle, "Assets/skeletal_hand.prefab");

            var feetPositionBundle = LoadBundle("feetposition");

            FeetPositionPrefab = LoadAsset <GameObject>(feetPositionBundle, "feetposition.prefab");

            var scopeLensBundle = LoadBundle("scope-lens");

            ScopeLensPrefab = LoadAsset <GameObject>(scopeLensBundle, "scopelens.prefab");

            var helmetBundle = LoadBundle("helmet");

            HelmetPrefab = LoadAsset <GameObject>(helmetBundle, "helmet.prefab");

            var lookArrowBundle = LoadBundle("look-arrow");

            LookArrowPrefab = LoadAsset <GameObject>(lookArrowBundle, "lookarrow.prefab");

            var splashBundle = LoadBundle("splash-screen");

            SplashSprite = LoadAsset <Sprite>(splashBundle, "splash.png");


            FallbackRelaxedPose = LoadModAssetFromJson <SteamVR_Skeleton_Pose>("poses/fallback_relaxed.json");
            FallbackPointPose   = LoadModAssetFromJson <SteamVR_Skeleton_Pose>("poses/fallback_point.json");
            FallbackFistPose    = LoadModAssetFromJson <SteamVR_Skeleton_Pose>("poses/fallback_fist.json");
            ReachForPose        = LoadModAssetFromJson <SteamVR_Skeleton_Pose>("poses/reachFor.json");
        }
        IEnumerator RebakePosesRoutine()
        {
            SimpleUI.UIManager.ShowGameMessage("testing animations");
            yield return(new WaitForSeconds(3));

            for (int i = 0; i < 4; i++)
            {
                SimpleUI.UIManager.ShowGameMessage("testing animation : " + i.ToString());
                getWorkingHand.GetComponentInChildren <Animator>().SetInteger("AnimationState", i);
                getWorkingHand.BlendToAnimation(.25f);
                yield return(new WaitForSeconds(1));

                SimpleUI.UIManager.ShowGameMessage("Baking...");
                yield return(new WaitForSeconds(1));

                SteamVR_Skeleton_Pose redonpose = MakeNewPose("_ANIMPOSE_" + i + ".asset", null);
                SaveHandData(redonpose.GetHand(baker.handToUse), getWorkingHand);
                CopyHand(redonpose, redonpose.GetHand(baker.handToUse), redonpose.GetHand(getOppositeHand.inputSource));

                yield return(new WaitForSeconds(3));

                SimpleUI.UIManager.ShowGameMessage("blendign bakc from : " + i.ToString());

                getWorkingHand.BlendToSkeleton(.25f);

                yield return(new WaitForSeconds(2));
            }



            SimpleUI.UIManager.ShowGameMessage("starting rebake routine");
            yield return(new WaitForSeconds(3));

            SteamVR_Input_Sources handToUse = baker.handToUse;

            foreach (SteamVR_Skeleton_Pose pose in baker.posesToBake)
            {
                string poseName = pose.name;
                SimpleUI.UIManager.ShowGameMessage("woking on pose: " + poseName);
                yield return(new WaitForSeconds(1));

                SimpleUI.UIManager.ShowGameMessage("setting psoe...");
                baker.GetComponent <SteamVR_Skeleton_Poser>().skeletonMainPose = pose;
                SetHandToPoserBehavior();
                yield return(new WaitForSeconds(1));

                SimpleUI.UIManager.ShowGameMessage("Baking...");

                SteamVR_Skeleton_Pose redonpose = MakeNewPose("_REDONE_" + poseName + ".asset", pose);
                SaveHandData(redonpose.GetHand(baker.handToUse), getWorkingHand);
                CopyHand(redonpose, redonpose.GetHand(baker.handToUse), redonpose.GetHand(getOppositeHand.inputSource));

                yield return(new WaitForSeconds(3));

                SimpleUI.UIManager.ShowGameMessage("Done Baking " + poseName);

                getWorkingHand.BlendToSkeleton(.25f);
                yield return(new WaitForSeconds(2));
            }



            yield return(new WaitForSeconds(1));

            SimpleUI.UIManager.ShowGameMessage("Done With ROUTINE! 5 seconds for finger TOP relaxed");
            yield return(new WaitForSeconds(5));

            SimpleUI.UIManager.ShowGameMessage("BAKING");

            SteamVR_Skeleton_Pose newPose = MakeNewPose("_TriggerHoldFingerTop_.asset", null);

            SaveHandData(newPose.GetHand(baker.handToUse), getWorkingHand);
            CopyHand(newPose, newPose.GetHand(baker.handToUse), newPose.GetHand(getOppositeHand.inputSource));
            yield return(new WaitForSeconds(1));

            SimpleUI.UIManager.ShowGameMessage("5 seconds for finger top BOTTOM");
            yield return(new WaitForSeconds(5));

            SimpleUI.UIManager.ShowGameMessage("BAKING");


            newPose = MakeNewPose("_TriggerHoldFingerbottom_.asset", null);
            SaveHandData(newPose.GetHand(baker.handToUse), getWorkingHand);
            CopyHand(newPose, newPose.GetHand(baker.handToUse), newPose.GetHand(getOppositeHand.inputSource));
            yield return(new WaitForSeconds(1));

            SimpleUI.UIManager.ShowGameMessage(" 5 seconds for finger top OFF");
            yield return(new WaitForSeconds(5));

            SimpleUI.UIManager.ShowGameMessage("BAKING");


            newPose = MakeNewPose("_TriggerHoldOff_.asset", null);
            SaveHandData(newPose.GetHand(baker.handToUse), getWorkingHand);
            CopyHand(newPose, newPose.GetHand(baker.handToUse), newPose.GetHand(getOppositeHand.inputSource));
            yield return(new WaitForSeconds(1));

            SimpleUI.UIManager.ShowGameMessage("Done With ROUTINE!");
        }
        void DeepCopyPose(SteamVR_Skeleton_Pose source, SteamVR_Skeleton_Pose dest)
        {
            int boneNum = SteamVR_Action_Skeleton.numBones;

            if (dest.rightHand.bonePositions == null)
            {
                dest.rightHand.bonePositions = new Vector3[boneNum];
            }
            if (dest.rightHand.boneRotations == null)
            {
                dest.rightHand.boneRotations = new Quaternion[boneNum];
            }

            if (dest.leftHand.bonePositions == null)
            {
                dest.leftHand.bonePositions = new Vector3[boneNum];
            }
            if (dest.leftHand.boneRotations == null)
            {
                dest.leftHand.boneRotations = new Quaternion[boneNum];
            }

            EditorUtility.SetDirty(dest);


            // RIGHT HAND COPY

            dest.rightHand.position = source.rightHand.position;
            dest.rightHand.rotation = source.rightHand.rotation;
            for (int boneIndex = 0; boneIndex < boneNum; boneIndex++)
            {
                dest.rightHand.bonePositions[boneIndex] = source.rightHand.bonePositions[boneIndex];
                dest.rightHand.boneRotations[boneIndex] = source.rightHand.boneRotations[boneIndex];
                // EditorUtility.DisplayProgressBar("Copying...", "Copying right hand pose", (float)boneIndex / (float)boneNum / 2f);
            }
            dest.rightHand.thumbFingerMovementType  = source.rightHand.thumbFingerMovementType;
            dest.rightHand.indexFingerMovementType  = source.rightHand.indexFingerMovementType;
            dest.rightHand.middleFingerMovementType = source.rightHand.middleFingerMovementType;
            dest.rightHand.ringFingerMovementType   = source.rightHand.ringFingerMovementType;
            dest.rightHand.pinkyFingerMovementType  = source.rightHand.pinkyFingerMovementType;

            // LEFT HAND COPY

            dest.leftHand.position = source.leftHand.position;
            dest.leftHand.rotation = source.leftHand.rotation;
            for (int boneIndex = 0; boneIndex < boneNum; boneIndex++)
            {
                dest.leftHand.bonePositions[boneIndex] = source.leftHand.bonePositions[boneIndex];
                dest.leftHand.boneRotations[boneIndex] = source.leftHand.boneRotations[boneIndex];
                // EditorUtility.DisplayProgressBar("Copying...", "Copying left hand pose", (float)boneIndex / (float)boneNum / 2f);
            }
            dest.leftHand.thumbFingerMovementType  = source.leftHand.thumbFingerMovementType;
            dest.leftHand.indexFingerMovementType  = source.leftHand.indexFingerMovementType;
            dest.leftHand.middleFingerMovementType = source.leftHand.middleFingerMovementType;
            dest.leftHand.ringFingerMovementType   = source.leftHand.ringFingerMovementType;
            dest.leftHand.pinkyFingerMovementType  = source.leftHand.pinkyFingerMovementType;

            EditorUtility.SetDirty(dest);

            // EditorUtility.ClearProgressBar();
        }
        void DrawPoseEditorMenu()
        {
            bool createNew = false;

            activePoseIndex = previewPoseSelection;    //.intValue;

            if (activePoseIndex >= 0 && activePoseIndex < allPosesProperty.arraySize)
            {
                activePoseProp = allPosesProperty.GetArrayElementAtIndex(activePoseIndex);
            }


            //box containing all pose editing controls
            GUILayout.BeginVertical("box");

            poseNames = new string[allPosesProperty.arraySize];

            for (int i = 0; i < allPosesProperty.arraySize; i++)
            {
                poseNames[i] = allPosesProperty.GetArrayElementAtIndex(i).objectReferenceValue == null ? "[not set]" : allPosesProperty.GetArrayElementAtIndex(i).objectReferenceValue.name;
            }

            //show selectable menu of all poses, highlighting the one that is selected
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();

            int poseSelected = EditorGUILayout.Popup("Current Pose:", activePoseIndex, poseNames);

            if (poseSelected != activePoseIndex)
            {
                activePoseIndex      = poseSelected;
                PoseChanged          = true;
                previewPoseSelection = activePoseIndex;
            }

            // EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(32));
            if (GUILayout.Button("+", GUILayout.MaxWidth(32)))
            {
                allPosesProperty.InsertArrayElementAtIndex(allPosesProperty.arraySize);
                allPosesProperty.GetArrayElementAtIndex(allPosesProperty.arraySize - 1).objectReferenceValue = null;
            }
            //only allow deletion of additional poses
            EditorGUI.BeginDisabledGroup(allPosesProperty.arraySize == 0 || activePoseIndex == 0);
            if (GUILayout.Button("-", GUILayout.MaxWidth(32)) && allPosesProperty.arraySize > 0)
            {
                allPosesProperty.DeleteArrayElementAtIndex(activePoseIndex);
                allPosesProperty.DeleteArrayElementAtIndex(activePoseIndex);
                if (activePoseIndex >= allPosesProperty.arraySize)
                {
                    activePoseIndex      = allPosesProperty.arraySize - 1;
                    previewPoseSelection = activePoseIndex;
                    return;
                }
            }
            EditorGUI.EndDisabledGroup();

            EditorGUILayout.EndHorizontal();

            GUILayout.BeginVertical(GUILayout.MaxWidth(200));


            if (PoseChanged)
            {
                PoseChanged = false;

                if (activePoseIndex >= 0 && activePoseIndex < allPosesProperty.arraySize)
                {
                    activePoseProp = allPosesProperty.GetArrayElementAtIndex(activePoseIndex);
                    activePose     = (SteamVR_Skeleton_Pose)activePoseProp.objectReferenceValue;
                }
            }

            if (activePoseProp != null)
            {
                activePose = (SteamVR_Skeleton_Pose)activePoseProp.objectReferenceValue;
                if (activePoseProp.objectReferenceValue == null)
                {
                    EditorGUILayout.BeginHorizontal();
                    activePoseProp.objectReferenceValue = EditorGUILayout.ObjectField(activePoseProp.objectReferenceValue, typeof(SteamVR_Skeleton_Pose), false);
                    if (GUILayout.Button("Create"))
                    {
                        createNew = true;
                    }
                    EditorGUILayout.EndHorizontal();
                    if (createNew)
                    {
                        string fullPath = EditorUtility.SaveFilePanelInProject("Create New Skeleton Pose", "newPose", "asset", "Save file");
                        if (string.IsNullOrEmpty(fullPath) == false)
                        {
                            SteamVR_Skeleton_Pose newPose = ScriptableObject.CreateInstance <SteamVR_Skeleton_Pose>();
                            AssetDatabase.CreateAsset(newPose, fullPath);
                            AssetDatabase.SaveAssets();

                            activePoseProp.objectReferenceValue = newPose;
                            serializedObject.ApplyModifiedProperties();
                        }
                    }
                }
                else
                {
                    activePoseProp.objectReferenceValue = EditorGUILayout.ObjectField(activePoseProp.objectReferenceValue, typeof(SteamVR_Skeleton_Pose), false);
                    GUILayout.BeginHorizontal();

                    EditorGUILayout.BeginVertical("box");
                    GUI.color = Color.white;
                    EditorGUIUtility.labelWidth = 24;
                    EditorGUILayout.LabelField("Left Hand", EditorStyles.boldLabel);
                    EditorGUIUtility.labelWidth = 0;
                    DrawHand(activePose.leftHand, activePose.rightHand);    //, getLeftFromOpposite);
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.BeginVertical("box");
                    EditorGUIUtility.labelWidth = 24;
                    EditorGUILayout.LabelField("Right Hand", EditorStyles.boldLabel);
                    EditorGUIUtility.labelWidth = 0;
                    DrawHand(activePose.rightHand, activePose.leftHand);    //, getRightFromOpposite);
                    EditorGUILayout.EndVertical();

                    GUILayout.EndHorizontal();
                }
            }

            EditorGUILayout.EndVertical();

            GUILayout.EndVertical();
        }
Example #11
0
        protected void UpdatePreviewHand(ref GameObject preview, ref bool showPreview, string assetName, SteamVR_Skeleton_Pose_Hand handData, SteamVR_Skeleton_Pose sourcePose, bool forceUpdate)
        {
            if (showPreview)
            {
                if (forceUpdate && preview != null)
                {
                    DestroyImmediate(preview);
                }

                if (preview == null)
                {
                    GameObject prefabProperty = null;
                    string[]   defPaths       = AssetDatabase.FindAssets(string.Format("t:Prefab {0}", assetName));
                    if (defPaths != null && defPaths.Length > 0)
                    {
                        string guid = defPaths[0];
                        string path = AssetDatabase.GUIDToAssetPath(guid);
                        prefabProperty = AssetDatabase.LoadAssetAtPath <GameObject>(path);

                        if (prefabProperty == null)
                        {
                            Debug.LogError("[SteamVR] Could not load prefab: " + assetName + ". Found path: " + path);
                        }
                    }
                    else
                    {
                        Debug.LogError("[SteamVR] Could not load prefab: " + assetName);
                    }

                    preview = GameObject.Instantiate(prefabProperty);
                    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 = handData.rotation;
                        preview.transform.localPosition = 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();
                }
            }
            else
            {
                if (preview != null)
                {
                    DestroyImmediate(preview);
                    SceneView.RepaintAll();
                }
            }
        }
Example #12
0
        void DrawPoseEditorMenu()
        {
            if (Application.isPlaying)
            {
                EditorGUILayout.LabelField("Cannot modify pose while in play mode.");
            }
            else
            {
                activePoseIndex = previewPoseSelection;//.intValue;

                activePoseProp = allPosesProperty.GetArrayElementAtIndex(activePoseIndex);

                //box containing all pose editing controls
                GUILayout.BeginVertical("box");

                //show selectable menu of all poses, highlighting the one that is selected
                EditorGUILayout.Space();

                poseNames = new string[allPosesProperty.arraySize];

                for (int i = 0; i < allPosesProperty.arraySize; i++)
                {
                    poseNames[i] = allPosesProperty.GetArrayElementAtIndex(i).objectReferenceValue == null ? "[not set]" : allPosesProperty.GetArrayElementAtIndex(i).objectReferenceValue.name;
                }

                int poseSelected = EditorGUILayout.Popup("Current Pose:", activePoseIndex, poseNames);


                if (poseSelected != activePoseIndex)
                {
                    forceUpdateHands     = true;
                    activePoseIndex      = poseSelected;
                    PoseChanged          = true;
                    previewPoseSelection = activePoseIndex;
                }
                if (PoseChanged)
                {
                    PoseChanged      = false;
                    forceUpdateHands = true;

                    activePoseProp = allPosesProperty.GetArrayElementAtIndex(activePoseIndex);
                    activePose     = (SteamVR_Skeleton_Pose)activePoseProp.objectReferenceValue;
                }
                activePose = (SteamVR_Skeleton_Pose)activePoseProp.objectReferenceValue;

                if (activePoseProp.objectReferenceValue == null)
                {
                    if (previewInstanceL != null)
                    {
                        DestroyImmediate(previewInstanceL);
                    }
                    if (previewInstanceR != null)
                    {
                        DestroyImmediate(previewInstanceR);
                    }
                }
                else
                {
                    DrawPoseControlButtons();

                    UpdatePreviewHand(ref previewInstanceL, ref showLeftPreview, leftDefaultAssetName, activePose.leftHand, activePose, forceUpdateHands);
                    UpdatePreviewHand(ref previewInstanceR, ref showRightPreview, rightDefaultAssetName, activePose.rightHand, activePose, forceUpdateHands);

                    forceUpdateHands = false;

                    if (handTexL == null)
                    {
                        handTexL = (Texture)EditorGUIUtility.Load("Assets/VRPlayerControl/SteamVR/Input/Editor/Resources/Icons/HandLeftIcon.png");
                    }
                    if (handTexR == null)
                    {
                        handTexR = (Texture)EditorGUIUtility.Load("Assets/VRPlayerControl/SteamVR/Input/Editor/Resources/Icons/HandRightIcon.png");
                    }


                    // GUILayout.EndVertical();

                    GUILayout.BeginHorizontal();
                    //Left Hand
                    EditorGUILayout.BeginVertical();
                    EditorGUILayout.BeginVertical("box");
                    EditorGUILayout.BeginHorizontal();


                    GUI.color = new Color(1, 1, 1, showLeftPreview ? 1 : 0.25f);
                    if (GUILayout.Button(handTexL, GUI.skin.label, GUILayout.Width(64), GUILayout.Height(64)))
                    {
                        showLeftPreview  = !showLeftPreview;
                        forceUpdateHands = true;
                    }



                    GUI.color = Color.white;

                    EditorGUIUtility.labelWidth = 48;
                    EditorGUILayout.LabelField("Left Hand", EditorStyles.boldLabel);
                    EditorGUIUtility.labelWidth = 0;
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();

                    DrawHand(showLeftPreview, activePose.leftHand, activePose.rightHand, getLeftFromOpposite);
                    EditorGUILayout.EndVertical();
                    EditorGUI.BeginDisabledGroup((showLeftPreview && showRightPreview) == false);
                    getRightFromOpposite = GUILayout.Button("Copy Left pose to Right hand");
                    EditorGUI.EndDisabledGroup();

                    EditorGUILayout.EndVertical();

                    EditorGUILayout.BeginVertical();

                    EditorGUILayout.BeginVertical("box");

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();
                    EditorGUIUtility.labelWidth = 48;
                    EditorGUILayout.LabelField("Right Hand", EditorStyles.boldLabel);
                    EditorGUIUtility.labelWidth = 0;
                    GUI.color = new Color(1, 1, 1, showRightPreview ? 1 : 0.25f);
                    if (GUILayout.Button(handTexR, GUI.skin.label, GUILayout.Width(64), GUILayout.Height(64)))
                    {
                        showRightPreview = !showRightPreview;    //showRightPreviewProperty.boolValue;
                        forceUpdateHands = true;
                    }
                    GUI.color = Color.white;
                    EditorGUILayout.EndHorizontal();


                    DrawHand(showRightPreview, activePose.rightHand, activePose.leftHand, getRightFromOpposite);

                    EditorGUILayout.EndVertical();


                    EditorGUI.BeginDisabledGroup((showLeftPreview && showRightPreview) == false);
                    getLeftFromOpposite = GUILayout.Button("Copy Right pose to Left hand");
                    EditorGUI.EndDisabledGroup();
                }

                GUILayout.EndVertical();
                EditorGUILayout.EndVertical();
                GUILayout.EndHorizontal();


                EditorGUI.BeginChangeCheck();
                EditorGUIUtility.labelWidth = 120;
                poserScale = EditorGUILayout.FloatField("Preview Pose Scale", poserScale);
                if (poserScale <= 0)
                {
                    poserScale = 1;
                }
                EditorGUIUtility.labelWidth = 0;

                if (EditorGUI.EndChangeCheck())
                {
                    forceUpdateHands = true;
                }
            }
        }
Example #13
0
        protected void DrawPoseControlButtons()
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical();


            activePoseProp.objectReferenceValue = EditorGUILayout.ObjectField(activePoseProp.objectReferenceValue, typeof(SteamVR_Skeleton_Pose), false);


            // GameObject leftInstance = previewLeftInstanceProperty.objectReferenceValue as GameObject;
            GameObject leftInstance = previewInstanceL;

            leftSkeleton = null;

            if (leftInstance != null)
            {
                leftSkeleton = leftInstance.GetComponent <SteamVR_Behaviour_Skeleton>();
            }

            GameObject rightInstance = previewInstanceR;

            rightSkeleton = null;

            if (rightInstance != null)
            {
                rightSkeleton = rightInstance.GetComponent <SteamVR_Behaviour_Skeleton>();
            }


            //only allow saving if a hand is opened for editing

            EditorGUI.BeginDisabledGroup(showRightPreview == false && showLeftPreview == false);
            GUI.color = new Color(0.9f, 1.0f, 0.9f);
            // save both hands at once, or whichever are being edited
            bool save = GUILayout.Button(string.Format("Save Pose"));

            if (save)
            {
                if (showRightPreview)
                {
                    SaveHandData(activePose.rightHand, rightSkeleton);
                }
                if (showLeftPreview)
                {
                    SaveHandData(activePose.leftHand, leftSkeleton);
                }
            }
            GUI.color = Color.white;
            EditorGUI.EndDisabledGroup();

            //MIRRORING
            //only allow mirroring if both hands are opened for editing
            EditorGUI.BeginDisabledGroup(showRightPreview == false || showLeftPreview == false);
            if (GUILayout.Button("Import Pose"))
            {
                CopyPoseSelect();
            }
            EditorGUI.EndDisabledGroup();


            EditorGUILayout.EndVertical();

            // GUILayout.Space(32);

            EditorGUILayout.BeginVertical();

            GUILayout.Label("Reference Pose:");
            // EditorGUILayout.Space();
            forceToReferencePose = (EVRSkeletalReferencePose)EditorGUILayout.EnumPopup(forceToReferencePose);
            GUI.color            = new Color(1.0f, 0.73f, 0.7f);
            bool forcePose = GUILayout.Button("RESET TO REFERENCE POSE");

            GUI.color = Color.white;

            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();

            if (forcePose)
            {
                bool confirm = EditorUtility.DisplayDialog("SteamVR", string.Format("This will overwrite your current skeleton data. (with data from the {0} reference pose)", forceToReferencePose.ToString()), "Overwrite", "Cancel");
                if (confirm)
                {
                    if (forceToReferencePose == EVRSkeletalReferencePose.GripLimit)
                    {
                        // grip limit is controller-specific, the rest use a baked pose
                        if (showLeftPreview)
                        {
                            leftSkeleton.ForceToReferencePose(forceToReferencePose);
                        }
                        if (showRightPreview)
                        {
                            rightSkeleton.ForceToReferencePose(forceToReferencePose);
                        }
                    }
                    else
                    {
                        SteamVR_Skeleton_Pose poseResource = null;
                        if (forceToReferencePose == EVRSkeletalReferencePose.OpenHand)
                        {
                            poseResource = (SteamVR_Skeleton_Pose)Resources.Load("ReferencePose_OpenHand");
                        }
                        if (forceToReferencePose == EVRSkeletalReferencePose.Fist)
                        {
                            poseResource = (SteamVR_Skeleton_Pose)Resources.Load("ReferencePose_Fist");
                        }
                        if (forceToReferencePose == EVRSkeletalReferencePose.BindPose)
                        {
                            poseResource = (SteamVR_Skeleton_Pose)Resources.Load("ReferencePose_BindPose");
                        }

                        DeepCopyPose(poseResource, activePose);
                    }
                }
            }
        }