コード例 #1
0
        private IEnumerator CheckSensorsRepeatedly()
        {
            const string  SensorFailureMessage = "Please restart the application";
            SlamLocalizer slamLocalizer        = GameObject.FindObjectOfType <SlamLocalizer>();

            //If the SLAM localizer is not being used then the sensor status cannot be read.
            if (!slamLocalizer)
            {
                yield break;
            }

            for (; ;)
            {
                //Wait until the sensors should be ready.
                if (!slamLocalizer.SlamFeedback.CameraReady)
                {
                    yield return(null);

                    continue;
                }

                //The IMU should be ready before the Camera is ready. If not then this is reported as an error.
                if (!slamLocalizer.SlamFeedback.HasFirstImu)
                {
                    _controller.ChangeMinorMessage(SensorFailureMessage);
                    _controller.SetTitleVisibility(true);
                }

                yield break;
            }
        }
コード例 #2
0
        /// <summary>
        /// Subscribe to the events of SlamLocalizer.
        /// </summary>
        /// <param name="localizer">Slam localizer</param>
        /// <returns>True if successful, false otherwise</returns>
        public bool ListenToSlamLocalizer(SlamLocalizer localizer)
        {
            if (localizer == null)
            {
                Debug.LogError("Given Slam Localizer is null");
                return(false);
            }

            localizer.onSlamTrackingLost.AddListener(OnSlamTrackingLost);
            localizer.onSlamTrackingRelocalized.AddListener(OnSlamTrackingRecovered);
            return(true);
        }
        /// <summary>
        /// Subscribe to the events of SlamLocalizer.
        /// </summary>
        /// <param name="localizer">Slam localizer</param>
        /// <returns>True if successful, false otherwise</returns>
        public bool ListenToSlamLocalizer(SlamLocalizer localizer)
        {
            if (localizer == null)
            {
                Debug.LogError("Given Slam Localizer is null");
                return(false);
            }
            _slamLocalizer = localizer;
            SubscribeToSlamLocalizer(true);

            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Handles assignment/removal of the canvas shown in place of the Webcam.
        /// </summary>
        /// <param name="changedToMode"></param>
        private void Start()
        {
            _sensorController = GetComponentInChildren <MetaSensorMessageController>();

            _slamLocalizer = GetComponent <SlamLocalizer>();
            _slamLocalizer.onSlamSensorsReady.AddListener(SlamInitCallback);

            Screen.SetResolution(1280, 720, false);
            _controller = ConstructCanvas();

            _compositor = GetComponent <MetaCompositor>();

            StartCoroutine(SetMessage());
        }
コード例 #5
0
        /// <summary>
        /// Generate the points for SLAM initialization that the user has to look at.
        /// TODO: If we go with the current version, only one point will be needed. If we go with the arrow version, all points are needed.
        /// </summary>
        private void Start()
        {
            // build all slam init points for the specified angle and step settings
            // "halfCircleCount * 2" pieces for "fromAngle" to "toAngle"
            // save them in an array
            // then do calibration fromIndex toIndex and use these points (activate/deactivate/show correct graphics/animation/light)

            _slamLocalizer = FindObjectOfType <SlamLocalizer>();

            if (eyeCamera == null)
            {
                eyeCamera = GameObject.Find("StereoCameras").transform;
            }

            if (eyeCamera == null)
            {
                Debug.LogError("Couldn't find stereo cameras!");
            }

            particles.gameObject.SetActive(false);
            leftArrows.gameObject.SetActive(useDirectionArrows);
            rightArrows.gameObject.SetActive(useDirectionArrows);

            var pointCount = useArrowAnimation ? stepCountHalfCircle * 2 : 1;

            pointCount = Mathf.RoundToInt(useArrowAnimation ? (stepCountHalfCircle * 2) : 1);

            _points = new SLAMInitializationGazePoint[pointCount];
            for (int i = 0; i < pointCount; i++)
            {
                var angle = Mathf.Lerp(-180, 180, (float)i / (pointCount + 1));

                SLAMInitializationGazePoint gazePoint = Instantiate(slamInitPrefab);
                gazePoint.EyeCamera               = eyeCamera;
                gazePoint.transform.parent        = transform;
                gazePoint.transform.localPosition = Vector3.zero;
                gazePoint.transform.localRotation = Quaternion.Euler(0, angle, 0);
                gazePoint.requiredLookAtTime      = lookAtTime;

                // initialize and hide these points
                // in non-arrow mode, they are invisible anyways
                gazePoint.direction = 1;
                gazePoint.Activate(false);
                gazePoint.number = i;
                gazePoint.slamUI = this;
                _points[i]       = gazePoint;
            }
        }
コード例 #6
0
        private void InitSlamLocalizerAnalytics()
        {
            SlamLocalizer slamLocalizer = GameObject.FindObjectOfType <SlamLocalizer>();

            if (slamLocalizer == null)
            {
                Debug.LogError(GetType() + ": Could not retrieve localizer.");
                return;
            }

            slamLocalizer.onSlamSensorsReady.AddListener(BeginLocalizationEvent);
            slamLocalizer.onSlamLocalizerResetEvent.AddListener(BeginLocalizationEvent);

            slamLocalizer.onSlamMappingComplete.AddListener(() => { EndLocalizationEvent(true); });
            slamLocalizer.onSlamInitializationFailed.AddListener(() => { EndLocalizationEvent(false); });
        }
コード例 #7
0
        private void EndLocalizationEvent(bool success)
        {
            SlamLocalizer slamLocalizer = GameObject.FindObjectOfType <SlamLocalizer>();

            if (slamLocalizer)
            {
                RecordSlamSuccessRate(success);
                _slamImuStartedOk = slamLocalizer.SlamFeedback.HasFirstImu;

                if (slamLocalizer.SlamInitializedFromLoadedMap && !_slamRelocalizationChanceSpent)
                {
                    _slamSuccessfulRelocalizationDuration = Time.fixedUnscaledTime - _slamInitBeginTime;
                    _slamRelocalizationSuccessful         = true;
                }
                else if (_slamBeganInitialization)
                {
                    _slamInitTimes.Add(Time.fixedUnscaledTime - _slamInitBeginTime);
                    _slamBeganInitialization = false;
                }

                _slamRelocalizationChanceSpent = true;
            }
        }