Пример #1
0
    /// <summary>
    /// HMDが見ている方向にあるノードを返す。
    /// </summary>
    /// <param name="hit">レイキャストの結果を格納する</param>
    /// <param name="allowReturnPrevNode">結果がnullだった際に前回見たノードを返すかどうか</param>
    /// <returns></returns>
    public static Node GetLookingNode(out RaycastHit hit, bool allowReturnPrevNode = true)
    {
        if (!_camera)
        {
            _camera = Camera.main;
        }

        var transform1 = _camera.transform;

        // var ray = new Ray(transform1.position, transform1.forward);
        SRanipal_Eye_v2.GetGazeRay(GazeIndex.COMBINE, out var ray);

        // レイキャストごとやってくれそうだけど、layermaskとかが無さそうだったから使ってない
        // var success = SRanipal_Eye_v2.Focus(GazeIndex.COMBINE, out var ray, out var info);

        ray.origin    = transform1.position;
        ray.direction = transform1.TransformDirection(ray.direction);
        Debug.DrawRay(ray.origin, ray.direction, Color.green);

        var hasHit = Physics.Raycast(ray, out hit, 10, LayerMask.GetMask("Node"));

        if (!hasHit)
        {
            return(allowReturnPrevNode ? _prevLookingNode : null);
        }

        var lookingNode = hit.transform.GetComponent <Node>();

        _prevLookingNode = lookingNode;
        return(lookingNode);
    }
Пример #2
0
    private void UpdateEyeOpenness(EyeIndex eyeIndex)
    {
        var anotherEye = eyeIndex == EyeIndex.RIGHT ? EyeIndex.LEFT : EyeIndex.RIGHT;

        SRanipal_Eye_v2.GetEyeOpenness(eyeIndex, out var currentOpenness);

        // 指定の目をつむっているとき
        if (currentOpenness < BlinkThreshold)
        {
            // 目を閉じてる経過時間を加算
            _closingTime[eyeIndex] += Time.deltaTime;

            // 前回の入力では空いてるとき (目をつむった瞬間)
            if (!_isClosing[eyeIndex])
            {
                // OnWink(eyeIndex);

                _closingTime[eyeIndex] = 0;

                //これはこのif文の最後でやる
                _isClosing[eyeIndex] = true;
            }
        }
        // 指定の目が空いているとき
        else
        {
            _closingTime[eyeIndex] = 0;
            _isClosing[eyeIndex]   = false;
        }

        _prevEyeOpenness[eyeIndex] = currentOpenness;
    }
Пример #3
0
    // ********************************************************************************************************************
    //
    //  Calibration is performed if the calibration is necessary.
    //
    // ********************************************************************************************************************
    void Calibration()
    {
        SRanipal_Eye_API.IsUserNeedCalibration(ref cal_need);           // Check the calibration status. If needed, we perform the calibration.

        if (cal_need == true)
        {
            result_cal = SRanipal_Eye_v2.LaunchEyeCalibration();

            if (result_cal == true)
            {
                Debug.Log("Calibration is done successfully.");
            }

            else
            {
                Debug.Log("Calibration is failed.");
                if (UnityEditor.EditorApplication.isPlaying)
                {
                    UnityEditor.EditorApplication.isPlaying = false;    // Stops Unity editor if the calibration if failed.
                }
            }
        }

        if (cal_need == false)
        {
            Debug.Log("Calibration is not necessary");
        }
    }
    //private void OnApplicationQuit()
    //{
    //	Debug.Log("OnApplicationQuit");
    //}
    //private void OnDisable()
    //{
    //	Debug.Log("OnDisable");
    //}

    //private void OnDestroy()
    //{
    //	Debug.Log("OnDestroy");
    //}


    void Update()
    {
        sLogChanges = logChanges;

        if (!isCallbackAdded && (SRanipal_Eye_Framework.Status == SRanipal_Eye_Framework.FrameworkStatus.WORKING || SRanipal_Eye_Framework.Status == SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT))
        {
            SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
            isCallbackAdded = true;
        }

        //if (isCallbackAdded != SRanipal_Eye_Framework.Instance.EnableEyeDataCallback)
        //{
        //	if (isCallbackAdded)
        //	{
        //		SRanipal_Eye_v2.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
        //		isCallbackAdded = false;
        //	}
        //	else
        //	{
        //		SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
        //		isCallbackAdded = true;
        //	}
        //}
        //Debug.Assert(isCallbackAdded == SRanipal_Eye_Framework.Instance.EnableEyeDataCallback);
    }
                private void Update()
                {
                    if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING &&
                        SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT)
                    {
                        return;
                    }

                    if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == true && eye_callback_registered == false)
                    {
                        SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                        eye_callback_registered = true;
                    }
                    else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false && eye_callback_registered == true)
                    {
                        SRanipal_Eye_v2.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                        eye_callback_registered = false;
                    }

                    Vector3 GazeOriginCombinedLocal, GazeDirectionCombinedLocal;

                    if (eye_callback_registered)
                    {
                        if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.COMBINE, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal, eyeData))
                        {
                        }
                        else if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.LEFT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal, eyeData))
                        {
                        }
                        else if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.RIGHT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal, eyeData))
                        {
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.COMBINE, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                        {
                        }
                        else if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.LEFT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                        {
                        }
                        else if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.RIGHT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                        {
                        }
                        else
                        {
                            return;
                        }
                    }

                    Vector3 GazeDirectionCombined = Camera.main.transform.TransformDirection(GazeDirectionCombinedLocal);

                    GazeRayRenderer.SetPosition(0, Camera.main.transform.position - Camera.main.transform.up * 0.05f);
                    GazeRayRenderer.SetPosition(1, Camera.main.transform.position + GazeDirectionCombined * LengthOfRay);
                }
 private void Release()
 {
     if (eye_callback_registered == true)
     {
         SRanipal_Eye_v2.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
         eye_callback_registered = false;
     }
 }
Пример #7
0
 // ********************************************************************************************************************
 //
 //  Start is called before the first frame update. The Start() function is performed only one time.
 //
 // ********************************************************************************************************************
 void Start()
 {
     InputUserID();                              // Check if the file with the same ID exists.
     Invoke("SystemCheck", 0.5f);                // System check.
     SRanipal_Eye_v2.LaunchEyeCalibration();     // Perform calibration for eye tracking.
     //Calibration();
     TargetPosition();                           // Implement the targets on the VR view.
     Invoke("Measurement", 0.5f);                // Start the measurement of ocular movements in a separate callback function.
 }
Пример #8
0
    private void Update()
    {
        SRanipal_Eye_v2.GetEyeOpenness(EyeIndex.LEFT, out var currentLeftOpenness);
        SRanipal_Eye_v2.GetEyeOpenness(EyeIndex.RIGHT, out var currentRightOpenness);

        UpdateEyeOpenness(EyeIndex.LEFT);
        UpdateEyeOpenness(EyeIndex.RIGHT);

        JudgeEyePattern();
    }
Пример #9
0
    void Update()
    {
        sLogChanges = logChanges;

        if (!isCallbackAdded && (SRanipal_Eye_Framework.Status == SRanipal_Eye_Framework.FrameworkStatus.WORKING || SRanipal_Eye_Framework.Status == SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT))
        {
            SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
            isCallbackAdded = true;
        }
    }
Пример #10
0
 public void StartCalibration()
 {
     if (SRanipal_Eye_v2.LaunchEyeCalibration())
     {
         Debug.Log("<color=green>calibration successful :)</color>");
         CalibrationManager.Instance.EyeCalibrationSuccessful();
     }
     else
     {
         Debug.Log("<color=red>calibration failed :(</color>");
     }
 }
Пример #11
0
        // Update is called once per frame
        void Update()
        {
            if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING &&
                SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT)
            {
                return;
            }

            if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == true && eye_callback_registered == false)
            {
                SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                eye_callback_registered = true;
            }
            else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false && eye_callback_registered == true)
            {
                SRanipal_Eye_v2.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                eye_callback_registered = false;
            }

            if (eye_callback_registered && streaming.isOn)
            {
                pupilLeftSize       = eyeData.verbose_data.left.pupil_diameter_mm;
                pupilRightSize      = eyeData.verbose_data.right.pupil_diameter_mm;
                gazeDirectionNorm   = eyeData.verbose_data.combined.eye_data.gaze_direction_normalized;
                gazeDirectionOrigin = eyeData.verbose_data.combined.eye_data.gaze_origin_mm;
            }

            if (streaming.isOn)
            {
                lslStatus.color = startedColor;
            }
            else
            {
                lslStatus.color = stoppedColor;
            }

            if (eye_callback_registered && eyeData.no_user)
            {
                eyeStatus.color = startedColor;
            }
            else
            {
                eyeStatus.color = stoppedColor;
            }

            sampleRate.text = "Sample rate: " + (int)(1000.0f / (nextTime - lastTime)) + " Hz";
        }
        private void Update()
        {
            if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING &&
                SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT)
            {
                return;
            }

            if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == true && eye_callback_registered == false)
            {
                SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                eye_callback_registered = true;
            }
            else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false && eye_callback_registered == true)
            {
                SRanipal_Eye_v2.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                eye_callback_registered = false;
            }

            foreach (GazeIndex index in GazePriority)
            {
                Ray  GazeRay;
                int  dart_board_layer_id = LayerMask.NameToLayer("NoReflection");
                bool eye_focus;
                if (eye_callback_registered)
                {
                    eye_focus = SRanipal_Eye_v2.Focus(index, out GazeRay, out FocusInfo, 0, MaxDistance, (1 << dart_board_layer_id), eyeData);
                }
                else
                {
                    eye_focus = SRanipal_Eye_v2.Focus(index, out GazeRay, out FocusInfo, 0, MaxDistance, (1 << dart_board_layer_id));
                }

                if (eye_focus)
                {
                    DartBoard dartBoard = FocusInfo.transform.GetComponent <DartBoard>();
                    if (dartBoard != null)
                    {
                        dartBoard.Focus(FocusInfo.point);
                    }
                    break;
                }
            }
        }
Пример #13
0
    // ********************************************************************************************************************
    //
    //  Measure eye movements in a callback function that HTC SRanipal provides.
    //
    // ********************************************************************************************************************
    void Measurement()
    {
        EyeParameter eye_parameter = new EyeParameter();

        SRanipal_Eye_API.GetEyeParameter(ref eye_parameter);
        Data_txt();

        if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == true && eye_callback_registered == false)
        {
            SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
            eye_callback_registered = true;
        }

        else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false && eye_callback_registered == true)
        {
            SRanipal_Eye_v2.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
            eye_callback_registered = false;
        }
    }
        /// <summary>
        /// Update is called once per frame
        /// </summary>
        void Update()
        {
            Debug.Log("update fugafuga");

            // check the status of the anipal engine before getting eye data
            if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING &&
                SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT)
            {
                return;
            }

            // the spells to use a callback function to get the measurement data at 120fps
            if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == true && eye_callback_registered == false)
            {
                SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                eye_callback_registered = true;
            }
            else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false && eye_callback_registered == true)
            {
                SRanipal_Eye_v2.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                eye_callback_registered = false;
            }
        }
                private void Update()
                {
                    if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING)
                    {
                        return;
                    }

                    if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == true && eye_callback_registered == false)
                    {
                        SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                        eye_callback_registered = true;
                    }
                    else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false && eye_callback_registered == true)
                    {
                        SRanipal_Eye_v2.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                        eye_callback_registered = false;
                    }

                    //When gaze ray data is valid, place the mirror gameobject directly in front of the player camera.
                    Ray  GazeRay;
                    bool get_gaze_ray;

                    if (eye_callback_registered == true)
                    {
                        get_gaze_ray = SRanipal_Eye_v2.GetGazeRay(GazeIndex.COMBINE, out GazeRay, eyeData);
                    }
                    else
                    {
                        get_gaze_ray = SRanipal_Eye_v2.GetGazeRay(GazeIndex.COMBINE, out GazeRay);
                    }
                    if (get_gaze_ray)
                    {
                        SetMirroTransform();
                        enabled = false;
                    }
                }
Пример #16
0
    private void FixedUpdate()
    {
        if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING &&
            SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT)
        {
            return;
        }



        if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == true && eyeCallbackRegistered == false)
        {
            SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(
                Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
            eyeCallbackRegistered = true;
        }
        else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false && eyeCallbackRegistered == true)
        {
            SRanipal_Eye_v2.WrapperUnRegisterEyeDataCallback(
                Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
            eyeCallbackRegistered = false;
        }

        foreach (GazeIndex index in gazePriority)
        {
            Ray  GazeRay;
            bool eye_focus;

            //eye call back should be enabled so we can get extra EyeData and save them in a logger
            if (eyeCallbackRegistered)
            {
                eye_focus = SRanipal_Eye_v2.Focus(index, out GazeRay, out focusInfo, 0,
                                                  maxDistance, ignoreLayerBitMask, EyeData);

                //Can be used if we don't want to specify layer to be ignored
                //eye_focus = SRanipal_Eye_v2.Focus(index, out GazeRay, out FocusInfo, 0, MaxDistance, eyeData);
            }
            else
            {
                eye_focus = SRanipal_Eye_v2.Focus(index, out GazeRay, out focusInfo, 0,
                                                  maxDistance, ignoreLayerBitMask);
            }
            //Debug.Log("Time_delta_unity: " + Time.deltaTime*1000 + "Time_unity: " + Time.time*1000 +
            //          " Frame_unity: " + Time.frameCount + " Time_ET: " + EyeData.timestamp +
            //          " Frame_ET: " + EyeData.frame_sequence);

            //ET Logging
            //if(focusInfo.collider != null) Debug.Log("Looking at: " + focusInfo.collider.gameObject.name);
            if (loggerInitialized)
            {
                logDataSb.Clear();
                //for 3D ET projection (collider hit) coordinate
                if (logEtPosition)
                {
                    logDataSb.Append(focusInfo.point.x + LoggerFormatDictionary["separatorFormat"] +
                                     focusInfo.point.y + LoggerFormatDictionary["separatorFormat"] +
                                     focusInfo.point.z);
                }
                //for collider hit name
                if (logFixatedObject)
                {
                    if (!string.IsNullOrEmpty(logData))
                    {
                        logDataSb.Append(LoggerFormatDictionary["separatorFormat"]);
                    }

                    if (focusInfo.collider == null)
                    {
                        if (eyeCallbackRegistered && EyeData.no_user)
                        {
                            fixationReport = "no user";
                        }
                        else
                        {
                            fixationReport = "no data";
                        }
                    }
                    else
                    {
                        fixationReport = focusInfo.collider.gameObject.name;
                    }
                    logDataSb.Append(fixationReport);
                }
                //extra data per left/right eye
                if (logBothEyes)
                {
                    //TODO...
                }
                //extra data per HTC eyetracker service variables
                if (logAccuracy)
                {
                    //TODO...
                }

                //finally, send to logger...
                Logger.GetComponent <PathScript>().logCustomData(logName, logDataSb.ToString(), this.gameObject);
            }

            //canvas logging
            if (logFixationToCanvas)
            {
                FixationCanvas.text = fixationReport;
            }

            if (eye_focus)
            {
                //renders user-point
                // the line has coordinates of gaze ray previosly calulated by Focus function
                if (renderGazeRay && gazeRayRenderer != null)
                {
                    Vector3 GazeDirectionCombined_FromFocus =
                        Camera.main.transform.TransformDirection(GazeRay.direction);
                    gazeRayRenderer.SetPosition(0, Camera.main.transform.position);
                    gazeRayRenderer.SetPosition(1, Camera.main.transform.position +
                                                GazeDirectionCombined_FromFocus * maxDistance);
                }

                if (drawGazeSphere)
                {
                    gazeSphere.transform.position = focusInfo.point;
                }
                break;
            }
        }
    }
Пример #17
0
        private void Update()
        {
            if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING)
            {
                return;
            }

            if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == true && _eyeCallbackRegistered == false)
            {
                SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                _eyeCallbackRegistered = true;
            }
            else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false && _eyeCallbackRegistered == true)
            {
                SRanipal_Eye_v2.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                _eyeCallbackRegistered = false;
            }

            bool eyeFocus = false;

            foreach (GazeIndex index in _gazePriority)
            {
                Ray gazeRay;

                if (_eyeCallbackRegistered)
                {
                    eyeFocus = SRanipal_Eye_v2.Focus(index, out gazeRay, out _focusInfo, 0, _maxDistance, trackedObjectLayers, _eyeData);
                }
                else
                {
                    eyeFocus = SRanipal_Eye_v2.Focus(index, out gazeRay, out _focusInfo, 0, _maxDistance, trackedObjectLayers);
                }

                if (eyeFocus)
                {
                    _previousObjectInFocus = _objectInFocus;
                    _objectInFocus         = _focusInfo.collider;

                    var previousTrackedObject = _trackedObject;
                    _trackedObject = _focusInfo.transform.GetComponent <TrackedObject>();
                    if (_trackedObject != null)
                    {
                        _trackedObjectInfo = new TrackedObjectInfo(_trackedObject.ObjectId, _focusInfo.distance);
                    }

                    if (_objectInFocus == _previousObjectInFocus)
                    {
                        //do nothing
                    }
                    else
                    {
                        if (previousTrackedObject != null)
                        {
                            ExitGaze(previousTrackedObject);
                        }

                        if (_trackedObject != null)
                        {
                            EnterGaze(_trackedObject);
                        }
                    }
                    break;
                }
            }
            if (!eyeFocus)
            {
                _previousObjectInFocus = null;
                _objectInFocus         = null;
                if (_trackedObject != null)
                {
                    ExitGaze(_trackedObject);
                }
                _trackedObject = null;
            }
        }
Пример #18
0
                private void Update()
                {
                    if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING &&
                        SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT)
                    {
                        return;
                    }

                    if (NeededToGetData)
                    {
                        if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == true && eye_callback_registered == false)
                        {
                            SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                            eye_callback_registered = true;
                        }
                        else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false && eye_callback_registered == true)
                        {
                            SRanipal_Eye_v2.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                            eye_callback_registered = false;
                        }
                        else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false)
                        {
                            SRanipal_Eye_API.GetEyeData_v2(ref eyeData);
                        }

                        //Debug.Log("[Eye v2] Openness = " + eyeData.verbose_data.left.eye_openness + ", " + eyeData.verbose_data.right.eye_openness);

                        bool isLeftEyeActive  = false;
                        bool isRightEyeAcitve = false;
                        if (SRanipal_Eye_Framework.Status == SRanipal_Eye_Framework.FrameworkStatus.WORKING)
                        {
                            isLeftEyeActive  = eyeData.verbose_data.left.GetValidity(SingleEyeDataValidity.SINGLE_EYE_DATA_GAZE_ORIGIN_VALIDITY);
                            isRightEyeAcitve = eyeData.verbose_data.right.GetValidity(SingleEyeDataValidity.SINGLE_EYE_DATA_GAZE_ORIGIN_VALIDITY);
                        }
                        else if (SRanipal_Eye_Framework.Status == SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT)
                        {
                            isLeftEyeActive  = true;
                            isRightEyeAcitve = true;
                        }

                        if (isLeftEyeActive || isRightEyeAcitve)
                        {
                            if (eye_callback_registered == true)
                            {
                                SRanipal_Eye_v2.GetEyeWeightings(out EyeWeightings, eyeData);
                            }
                            else
                            {
                                SRanipal_Eye_v2.GetEyeWeightings(out EyeWeightings);
                            }
                            UpdateEyeShapes(EyeWeightings);
                        }
                        else
                        {
                            for (int i = 0; i < (int)EyeShape.Max; ++i)
                            {
                                bool isBlink = ((EyeShape)i == EyeShape.Eye_Left_Blink || (EyeShape)i == EyeShape.Eye_Right_Blink);
                                EyeWeightings[(EyeShape)i] = isBlink ? 1 : 0;
                            }

                            UpdateEyeShapes(EyeWeightings);

                            return;
                        }

                        Vector3 GazeOriginCombinedLocal, GazeDirectionCombinedLocal = Vector3.zero;
                        if (eye_callback_registered == true)
                        {
                            if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.COMBINE, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal, eyeData))
                            {
                            }
                            else if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.LEFT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal, eyeData))
                            {
                            }
                            else if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.RIGHT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal, eyeData))
                            {
                            }
                        }
                        else
                        {
                            if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.COMBINE, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                            {
                            }
                            else if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.LEFT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                            {
                            }
                            else if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.RIGHT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                            {
                            }
                        }
                        UpdateGazeRay(GazeDirectionCombinedLocal);
                    }
                }
Пример #19
0
        public EyeTrackingMenu(Transform pageRoot)
        {
            Root = pageRoot.gameObject;
            var leftEye = pageRoot.Find("EyeIndicators/LeftEye/Mask/XYLines");
            var rightEye = pageRoot.Find("EyeIndicators/RightEye/Mask/XYLines");
            
            _leftEyeVisualizer = new XYVisualizer(leftEye.Find("X"), leftEye.Find("Y"));
            _rightEyeVisualizer = new XYVisualizer(rightEye.Find("X"), rightEye.Find("Y"));

            _trackingToggle = new ToggleButton(pageRoot.Find("UtilButtons/ToggleActive"));
            _trackingToggle.OnToggle += b => SRanipalTrack.EyeEnabled = b;
            
            pageRoot.Find("UtilButtons/Recalibrate").GetComponent<Button>().onClick.AddListener((Action)(() => SRanipal_Eye_v2.LaunchEyeCalibration()));
        }
                private void Update()
                {
                    if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING &&
                        SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT)
                    {
                        return;
                    }

                    if (NeededToGetData)
                    {
                        if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == true && eye_callback_registered == false)
                        {
                            SRanipal_Eye_v2.WrapperRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                            eye_callback_registered = true;
                        }
                        else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false && eye_callback_registered == true)
                        {
                            SRanipal_Eye_v2.WrapperUnRegisterEyeDataCallback(Marshal.GetFunctionPointerForDelegate((SRanipal_Eye_v2.CallbackBasic)EyeCallback));
                            eye_callback_registered = false;
                        }
                        else if (SRanipal_Eye_Framework.Instance.EnableEyeDataCallback == false)
                        {
                            SRanipal_Eye_API.GetEyeData_v2(ref eyeData);
                        }

                        bool isLeftEyeActive  = false;
                        bool isRightEyeAcitve = false;
                        if (SRanipal_Eye_Framework.Status == SRanipal_Eye_Framework.FrameworkStatus.WORKING)
                        {
                            isLeftEyeActive  = eyeData.no_user;
                            isRightEyeAcitve = eyeData.no_user;
                        }
                        else if (SRanipal_Eye_Framework.Status == SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT)
                        {
                            isLeftEyeActive  = true;
                            isRightEyeAcitve = true;
                        }

                        if (isLeftEyeActive || isRightEyeAcitve)
                        {
                            if (eye_callback_registered == true)
                            {
                                SRanipal_Eye_v2.GetEyeWeightings(out EyeWeightings, eyeData);
                            }
                            else
                            {
                                SRanipal_Eye_v2.GetEyeWeightings(out EyeWeightings);
                            }
                            UpdateEyeShapes(EyeWeightings);
                        }
                        else
                        {
                            for (int i = 0; i < (int)EyeShape_v2.Max; ++i)
                            {
                                bool isBlink = ((EyeShape_v2)i == EyeShape_v2.Eye_Left_Blink || (EyeShape_v2)i == EyeShape_v2.Eye_Right_Blink);
                                EyeWeightings[(EyeShape_v2)i] = isBlink ? 1 : 0;
                            }

                            UpdateEyeShapes(EyeWeightings);

                            return;
                        }

                        Vector3 GazeOriginCombinedLocal, GazeDirectionCombinedLocal = Vector3.zero;
                        if (eye_callback_registered == true)
                        {
                            if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.COMBINE, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal, eyeData))
                            {
                            }
                            else if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.LEFT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal, eyeData))
                            {
                            }
                            else if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.RIGHT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal, eyeData))
                            {
                            }
                        }
                        else
                        {
                            if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.COMBINE, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                            {
                            }
                            else if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.LEFT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                            {
                            }
                            else if (SRanipal_Eye_v2.GetGazeRay(GazeIndex.RIGHT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal))
                            {
                            }
                        }
                        UpdateGazeRay(GazeDirectionCombinedLocal);
                    }
                }