Ejemplo n.º 1
0
        public virtual void UpdateIKTargets()
        {
            if (Application.isPlaying)
            {
                //1) Update all the IKTargets taking into consideration its ControlType.
                for (IKBone ikBone = IKBone.Hips; ikBone < IKBone.LastBone; ikBone++)
                {
                    ControlType    cType  = GetIKControl(ikBone);
                    HumanBodyBones boneID = ToHumanBodyBones(ikBone);
                    GetIKSolver(ikBone)._enableIK = cType != ControlType.Animation;

                    if (cType == ControlType.Tracking)
                    {
                        QuickVRNode node = _vrPlayArea.GetVRNode(boneID);
                        if (node.IsTracked())
                        {
                            //Update the QuickVRNode's position
                            UpdateIKTargetPosFromUser(node, boneID);

                            //Update the QuickVRNode's rotation
                            UpdateIKTargetRotFromUser(node, boneID);

                            if (boneID == HumanBodyBones.Head)
                            {
                                QuickIKSolver ikSolverHead = GetIKSolver(IKBone.Head);
                                if (!_applyHeadPosition)
                                {
                                    ikSolverHead._weightIKPos = 0;
                                }
                                if (!_applyHeadRotation)
                                {
                                    ikSolverHead._weightIKRot = 0;
                                }
                            }
                            else if (boneID == HumanBodyBones.LeftEye || boneID == HumanBodyBones.RightEye)
                            {
                                QuickIKSolverEye ikSolver = (QuickIKSolverEye)_animator.GetComponent <QuickIKManager>().GetIKSolver(boneID);
                                ikSolver._weightBlink = ((QuickVRNodeEye)node).GetBlinkFactor();
                            }
                        }
                    }
                }

                //2) Special case. If the Hips is set to Tracking mode, we need to adjust the IKTarget position of the hips
                //in a way that the head will match the position of the camera provided by the HMD
                if (GetIKControl(IKBone.Hips) == ControlType.Tracking)
                {
                    QuickIKSolver ikSolverHips = GetIKSolver(IKBone.Hips);
                    QuickIKSolver ikSolverHead = GetIKSolver(IKBone.Head);
                    float         chainLength  = Vector3.Distance(_animator.GetBoneTransform(HumanBodyBones.Hips).position, _animator.GetBoneTransform(HumanBodyBones.Head).position);
                    Vector3       v            = (ikSolverHips._targetLimb.position - ikSolverHead._targetLimb.position).normalized;
                    ikSolverHips._targetLimb.position = ikSolverHead._targetLimb.position + v * chainLength;
                }

                UpdateVRCursors();
                _footprints.gameObject.SetActive(_useFootprints);
            }
        }
        protected virtual void DrawIKSolverPropertiesBase(QuickIKSolver ikSolver)
        {
            EditorGUILayout.BeginHorizontal();
            GUI.enabled = false;
            EditorGUILayout.ObjectField("IKTarget", ikSolver._targetLimb, typeof(Transform), true);
            GUI.enabled = true;
            if (DrawButton("Reset", GUILayout.Width(52)))
            {
                ikSolver.LoadPose();
                //_target.ResetIKTarget(boneID);
            }
            EditorGUILayout.EndHorizontal();

            ikSolver._weightIKPos = EditorGUILayout.Slider("IKPosWeight", ikSolver._weightIKPos, 0, 1);
            ikSolver._weightIKRot = EditorGUILayout.Slider("IKRotWeight", ikSolver._weightIKRot, 0, 1);

            if (ikSolver.GetType() == typeof(QuickIKSolverEye))
            {
                QuickIKSolverEye ikSolverEye = (QuickIKSolverEye)ikSolver;
                if (ikSolverEye._showAngleLimits = FoldoutBolt(ikSolverEye._showAngleLimits, "Angle Limits"))
                {
                    EditorGUI.indentLevel++;
                    ikSolverEye._angleLimitLeft  = EditorGUILayout.FloatField("Left", ikSolverEye._angleLimitLeft);
                    ikSolverEye._angleLimitRight = EditorGUILayout.FloatField("Right", ikSolverEye._angleLimitRight);
                    ikSolverEye._angleLimitDown  = EditorGUILayout.FloatField("Down", ikSolverEye._angleLimitDown);
                    ikSolverEye._angleLimitUp    = EditorGUILayout.FloatField("Up", ikSolverEye._angleLimitUp);
                    EditorGUI.indentLevel--;
                }
                ikSolverEye._leftRight = EditorGUILayout.Slider("Left - Right", ikSolverEye._leftRight, ikSolverEye._angleLimitLeft, ikSolverEye._angleLimitRight);
                ikSolverEye._downUp    = EditorGUILayout.Slider("Down - Up", ikSolverEye._downUp, ikSolverEye._angleLimitDown, ikSolverEye._angleLimitUp);

                if (ikSolverEye._showBlinking = FoldoutBolt(ikSolverEye._showBlinking, "Blinking"))
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.Space();
                    if (DrawButton("Add"))
                    {
                        ikSolverEye._blinking.Add(new QuickIKSolverEye.BlinkData());
                    }
                    if (DrawButton("Remove Last"))
                    {
                        if (ikSolverEye._blinking.Count > 0)
                        {
                            ikSolverEye._blinking.RemoveAt(ikSolverEye._blinking.Count - 1);
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.Space();
                    for (int i = 0; i < ikSolverEye._blinking.Count; i++)
                    {
                        QuickIKSolverEye.BlinkData bData = ikSolverEye._blinking[i];

                        if (bData._showInInspector = FoldoutBolt(bData._showInInspector, "Element " + i.ToString()))
                        {
                            EditorGUI.indentLevel++;

                            bData._renderer = (SkinnedMeshRenderer)EditorGUILayout.ObjectField("Mesh", bData._renderer, typeof(SkinnedMeshRenderer), true);
                            if (bData._renderer && bData._renderer.sharedMesh)
                            {
                                Mesh          mesh   = bData._renderer.sharedMesh;
                                List <string> bNames = new List <string>();
                                bNames.Add("None");
                                for (int j = 0; j < mesh.blendShapeCount; j++)
                                {
                                    bNames.Add(mesh.GetBlendShapeName(j));
                                }

                                bData._blendshapeID = EditorGUILayout.Popup("Blendshape ID", bData._blendshapeID + 1, bNames.ToArray()) - 1;
                            }

                            EditorGUI.indentLevel--;
                        }
                    }

                    EditorGUILayout.Space();

                    EditorGUI.indentLevel--;
                }

                ikSolverEye._weightBlink = EditorGUILayout.Slider("BlinkWeight", ikSolverEye._weightBlink, 0, 1);
            }
        }