예제 #1
0
        public void CreateSession(NRSessionBehaviour session)
        {
            if (IsInitialized || session == null)
            {
                return;
            }
            if (NRSessionBehaviour != null)
            {
                NRDebugger.LogError("Multiple SessionBehaviour components cannot exist in the scene. " +
                                    "Destroying the newest.");
                GameObject.DestroyImmediate(session.gameObject);
                return;
            }
            NRDevice.Instance.Init();
            NativeAPI = new NativeInterface();
#if !UNITY_EDITOR_OSX
            NativeAPI.NativeTracking.Create();
#endif
            NRSessionBehaviour = session;

            NRHMDPoseTracker = session.GetComponent <NRHMDPoseTracker>();
            TrackingMode mode = NRHMDPoseTracker.TrackingMode == TrackingType.Tracking3Dof ? TrackingMode.MODE_3DOF : TrackingMode.MODE_6DOF;
            SetTrackingMode(mode);

            this.DeployData();

            NRKernalUpdater.Instance.OnUpdate += NRFrame.OnUpdate;
        }
        public void UpdateConfig(NRSessionConfig config)
        {
            if (m_ConfigHandle == 0)
            {
                m_ConfigHandle = this.Create();
            }

            if (m_ConfigHandle == 0)
            {
                NRDebugger.LogError("Faild to Create ARSessionConfig!!!");
                return;
            }

            var plane_find_mode = this.GetPlaneFindMode(m_ConfigHandle);

            if (plane_find_mode != config.PlaneFindingMode)
            {
                SetPlaneFindMode(m_ConfigHandle, config.PlaneFindingMode);
            }

            if (config.ImageTrackingMode != m_ImageTrackingMode)
            {
                //Trackable Image
                switch (config.ImageTrackingMode)
                {
                case TrackableImageFindingMode.DISABLE:
                    if (m_DatabaseHandle != 0)
                    {
                        m_NativeTrackableImage.DestroyDataBase(m_DatabaseHandle);
                        m_DatabaseHandle = 0;
                    }
                    var result = SetTrackableImageDataBase(m_ConfigHandle, 0);
                    NRDebugger.Log("[Disable trackable image] result : " + result);
                    break;

                case TrackableImageFindingMode.ENABLE:
                    if (config.TrackingImageDatabase != null)
                    {
                        m_DatabaseHandle = m_NativeTrackableImage.CreateDataBase();
                        result           = m_NativeTrackableImage.LoadDataBase(m_DatabaseHandle, config.TrackingImageDatabase.TrackingImageDataPath);
                        NRDebugger.LogFormat("[LoadDataBase] path:{0} result:{1} ", config.TrackingImageDatabase.TrackingImageDataPath, result);
                        result = SetTrackableImageDataBase(m_ConfigHandle, m_DatabaseHandle);
                        NRDebugger.Log("[SetTrackableImageDataBase] result : " + result);
                    }
                    else
                    {
                        result = SetTrackableImageDataBase(m_ConfigHandle, 0);
                        NRDebugger.Log("[Disable trackable image] result : " + result);
                    }
                    break;

                default:
                    break;
                }

                m_ImageTrackingMode = config.ImageTrackingMode;
            }
        }
예제 #3
0
        public void CreateSession(NRSessionBehaviour session)
        {
            if (SessionState != SessionState.UnInitialized && SessionState != SessionState.Destroyed)
            {
                return;
            }

            if (NRSessionBehaviour != null)
            {
                NRDebugger.LogError("Multiple SessionBehaviour components cannot exist in the scene. " +
                                    "Destroying the newest.");
                GameObject.DestroyImmediate(session.gameObject);
                return;
            }
            NRSessionBehaviour = session;
            NRHMDPoseTracker   = session.GetComponent <NRHMDPoseTracker>();

            try
            {
                NRDevice.Instance.Init();
            }
            catch (Exception)
            {
                throw;
            }

            NativeAPI = new NativeInterface();
            AsyncTaskExecuter.Instance.RunAction(() =>
            {
                NRDebugger.Log("AsyncTaskExecuter: Create tracking");
                switch (NRHMDPoseTracker.TrackingMode)
                {
                case NRHMDPoseTracker.TrackingType.Tracking6Dof:
                    NativeAPI.NativeTracking.Create();
                    NativeAPI.NativeTracking.SetTrackingMode(TrackingMode.MODE_6DOF);
                    break;

                case NRHMDPoseTracker.TrackingType.Tracking3Dof:
                    NativeAPI.NativeTracking.Create();
                    NRSessionBehaviour.SessionConfig.PlaneFindingMode  = TrackablePlaneFindingMode.DISABLE;
                    NRSessionBehaviour.SessionConfig.ImageTrackingMode = TrackableImageFindingMode.DISABLE;
                    NativeAPI.NativeTracking.SetTrackingMode(TrackingMode.MODE_3DOF);
                    break;

                default:
                    break;
                }
            });

            NRKernalUpdater.Instance.OnUpdate -= Update;
            NRKernalUpdater.Instance.OnUpdate += Update;

            SessionState = SessionState.Initialized;

            LoadNotification();
        }
 private void InitNativeController()
 {
     m_NativeController = new NativeController();
     if (m_NativeController.Init())
     {
         Inited = true;
         NRDebugger.Log("NRControllerProvider Init Succeed");
     }
     else
     {
         m_NativeController = null;
         NRDebugger.LogError("NRControllerProvider Init Failed !!");
     }
     m_NeedInit = false;
 }
        private void UpdatePoseByeTrackingType(Pose pose)
        {
            switch (m_TrackingType)
            {
            case TrackingType.RotationAndPosition:
                if (UseRelativeTransform)
                {
                    transform.localRotation = pose.rotation;
                    transform.localPosition = pose.position;
                }
                else
                {
                    transform.rotation = pose.rotation;
                    transform.position = pose.position;
                }
                NRDebugger.LogError(pose.ToString());
                break;

            case TrackingType.RotationOnly:
                if (UseRelativeTransform)
                {
                    transform.localRotation = pose.rotation;
                }
                else
                {
                    transform.rotation = pose.rotation;
                }
                break;

            case TrackingType.PositionOnly:
                if (UseRelativeTransform)
                {
                    transform.localPosition = pose.position;
                }
                else
                {
                    transform.position = pose.position;
                }
                break;

            default:
                break;
            }
        }
예제 #6
0
        public void CreateSession(NRSessionBehaviour session)
        {
            if (SessionState != SessionState.UnInitialized && SessionState != SessionState.Destroyed)
            {
                return;
            }
            if (NRSessionBehaviour != null)
            {
                NRDebugger.LogError("Multiple SessionBehaviour components cannot exist in the scene. " +
                                    "Destroying the newest.");
                GameObject.DestroyImmediate(session.gameObject);
                return;
            }
            NRSessionBehaviour = session;
            NRHMDPoseTracker   = session.GetComponent <NRHMDPoseTracker>();

            try
            {
                NRDevice.Instance.Init();
                NRDevice.Instance.CreateGlassesController();
                NRDevice.Instance.CreateHMD();
            }
            catch (Exception)
            {
                throw;
            }

            NativeAPI = new NativeInterface();
            NativeAPI.NativeTracking.Create();
            bool         is3dof = (NRHMDPoseTracker.TrackingMode == NRHMDPoseTracker.TrackingType.Tracking3Dof);
            TrackingMode mode   = is3dof ? TrackingMode.MODE_3DOF : TrackingMode.MODE_6DOF;

            if (mode == TrackingMode.MODE_3DOF)
            {
                NRSessionBehaviour.SessionConfig.PlaneFindingMode  = TrackablePlaneFindingMode.DISABLE;
                NRSessionBehaviour.SessionConfig.ImageTrackingMode = TrackableImageFindingMode.DISABLE;
            }
            NativeAPI.NativeTracking.SetTrackingMode(mode);

            NRKernalUpdater.Instance.OnUpdate -= Update;
            NRKernalUpdater.Instance.OnUpdate += Update;

            SessionState = SessionState.Initialized;
        }
예제 #7
0
        private static void QueueFrame(IntPtr textureptr, int size, UInt64 timestamp)
        {
            if (!isRGBCamStart)
            {
                NRDebugger.LogError("rgb camera not stopped properly, it still sending data.");
                return;
            }
            RGBRawDataFrame frame  = FramePool.Get <RGBRawDataFrame>();
            bool            result = RGBRawDataFrame.MakeSafe(TexturePtr, size, timestamp, ref frame);

            if (result)
            {
                m_RGBFrames.Enqueue(frame);
            }
            else
            {
                FramePool.Put <RGBRawDataFrame>(frame);
            }
        }
예제 #8
0
        private void InitNativeController()
        {
            m_NativeController = new NativeController();
            if (m_NativeController.Init())
            {
                Inited = true;
                NRDebugger.Log("NRControllerProvider Init Succeed");
            }
            else
            {
                m_NativeController = null;
                NRDebugger.LogError("NRControllerProvider Init Failed !!");
            }

#if !UNITY_EDITOR
            NRDebugger.Log("[NRInput] version:" + GetVersion(0));
#endif
            m_NeedInit = false;
        }
예제 #9
0
        private void Update()
        {
            if (Trackable == null)
            {
                NRDebugger.LogError("NRAnchor components instantiated outside of NRInternel are not supported. " +
                                    "Please use a 'Create' method within NRInternel to instantiate anchors.");
                return;
            }

            if (IsSessionDestroyed())
            {
                return;
            }

            var pose = Trackable.GetCenterPose();

            transform.position = pose.position;
            transform.rotation = pose.rotation;
        }
예제 #10
0
        public void CreateSession(NRSessionBehaviour session)
        {
            if (SessionBehaviour != null)
            {
                NRDebugger.LogError("Multiple SessionBehaviour components cannot exist in the scene. " +
                                    "Destroying the newest.");
                GameObject.Destroy(session);
                return;
            }
            NativeAPI = new NativeInterface();
#if !UNITY_EDITOR_OSX
            SessionStatus = NativeAPI.NativeTracking.Create() ? SessionState.Created : SessionState.UnInitialize;
#endif
            SessionBehaviour = session;

            NRHMDPoseTracker = session.GetComponent <NRHMDPoseTracker>();
            TrackingMode mode = NRHMDPoseTracker.TrackingMode == TrackingType.Tracking3Dof ? TrackingMode.MODE_3DOF : TrackingMode.MODE_6DOF;
            SetTrackingMode(mode);

            this.DeployData();
        }
예제 #11
0
        private void Init()
        {
            if (m_IsInit)
            {
                return;
            }

            try
            {
                NRDevice.Instance.Init();
            }
            catch (Exception e)
            {
                NRDebugger.LogError("[NRVirtualDisplayer] NRDevice init error:" + e.ToString());
                throw;
            }

            transform.position = m_StartPos;
            this.SetVirtualDisplayResolution();
            NRSessionManager.Instance.VirtualDisplayer = this;
            NRDebugger.Log("[NRVirtualDisplayer] Init");

#if !UNITY_EDITOR
            //m_RenderTexturePtr = m_ControllerScreen.GetNativeTexturePtr();
            NativeMultiDisplay = new NativeMultiDisplay();
            NativeMultiDisplay.Create();
            //NativeMultiDisplay.InitColorSpace();
            NativeMultiDisplay.ListenMainScrResolutionChanged(OnDisplayResolutionChanged);
            NativeMultiDisplay.Start();
            // Creat multiview controller..
            //GL.IssuePluginEvent(RenderThreadHandlePtr, 0);
            //LoadPhoneScreen();
#elif UNITY_EDITOR
            InitEmulator();
#endif
            m_VirtualController?.Init();
            m_IsInit = true;
            OnMultiDisplayInited?.Invoke();
            IsPlaying = true;
        }
        public static GameObject CreateControllerVisualObject(ControllerVisualType visualType)
        {
            GameObject visualObj  = null;
            string     prefabPath = "";
            string     folderPath = "ControllerVisuals/";

            switch (visualType)
            {
            case ControllerVisualType.NrealLight:
                prefabPath = folderPath + "nreal_light_controller_visual";
                break;

            case ControllerVisualType.Phone:
                prefabPath = folderPath + "phone_controller_visual";
                break;

            case ControllerVisualType.FinchShift:
                prefabPath = folderPath + "finch_shift_controller_visual";
                break;

            default:
                NRDebugger.LogError("Can not find controller visual for: " + visualType + ", set to default visual");
                prefabPath = folderPath + "nreal_light_controller_visual";
                break;
            }
            if (!string.IsNullOrEmpty(prefabPath))
            {
                GameObject controllerPrefab = Resources.Load <GameObject>(prefabPath);
                if (controllerPrefab)
                {
                    visualObj = GameObject.Instantiate(controllerPrefab);
                }
            }
            if (visualObj == null)
            {
                NRDebugger.LogError("Create controller visual failed, prefab path:" + prefabPath);
            }
            return(visualObj);
        }
        private void CreateControllerVisual(int index, ControllerVisualType visualType)
        {
            GameObject visualGo = ControllerVisualFactory.CreateControllerVisualObject(visualType);

            if (visualGo == null)
            {
                return;
            }
            m_ControllerVisuals[index] = visualGo.GetComponent <IControllerVisual>();
            if (m_ControllerVisuals[index] != null)
            {
                ControllerAnchorEnum ancherEnum = (index == 0 ? ControllerAnchorEnum.RightModelAnchor : ControllerAnchorEnum.LeftModelAnchor);
                visualGo.transform.parent        = NRInput.AnchorsHelper.GetAnchor(ancherEnum);
                visualGo.transform.localPosition = Vector3.zero;
                visualGo.transform.localRotation = Quaternion.identity;
                visualGo.transform.localScale    = Vector3.one;
            }
            else
            {
                NRDebugger.LogError("The ControllerVisual prefab:" + visualGo.name + " does not contain IControllerVisual interface");
                Destroy(visualGo);
            }
        }
        public void ParserControllerState(ControllerState state)
        {
            try
            {
                _touch_status = (Mathf.Abs(state.touchPos.x) > PRECISION || Mathf.Abs(state.touchPos.y) > PRECISION);
                if (!_touch_status)
                {
                    _touch.x = 0f;
                    _touch.y = 0f;
                }
                else
                {
                    _touch.x = state.touchPos.x;
                    _touch.y = state.touchPos.y;
                }

                UpdateCurrentTouchArea();
                lock (_buttons)
                {
                    lock (_down)
                    {
                        for (int i = 0; i < _buttons.Length; ++i)
                        {
                            _down[i] = _buttons[i];
                        }
                    }

                    _physical_button_down = _physical_button;
                    _physical_button      = state.GetButton(ControllerButton.TRIGGER);

                    if (_current_down_btn != -1)
                    {
                        _buttons[_current_down_btn] = _physical_button;
                        if (!_buttons[_current_down_btn])
                        {
                            _current_down_btn = -1;
                        }
                    }
                    else
                    {
                        _buttons[0] = false;  //Trigger
                        _buttons[1] = false;  //App
                        _buttons[2] = false;  //Home

                        bool _is_down = !_physical_button_down & _physical_button;
                        if (_currentTouchArea == TouchAreaEnum.Center)
                        {
                            _buttons[0] = _physical_button && _is_down;
                        }
                        else if (_currentTouchArea == TouchAreaEnum.Up)
                        {
                            _buttons[1] = _physical_button && _is_down;
                        }
                        else if (_currentTouchArea == TouchAreaEnum.Down)
                        {
                            _buttons[2] = _physical_button && _is_down;
                        }

                        _current_down_btn = -1;
                        for (int i = 0; i < 3; i++)
                        {
                            if (_buttons[i])
                            {
                                _current_down_btn = i;
                                break;
                            }
                        }
                    }

                    lock (_buttons_up)
                    {
                        lock (_buttons_down)
                        {
                            for (int i = 0; i < _buttons.Length; ++i)
                            {
                                _buttons_up[i]   = (_down[i] & !_buttons[i]);
                                _buttons_down[i] = (!_down[i] & _buttons[i]);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                NRDebugger.LogError("Controller Data Error :" + e.ToString());
            }

            state.isTouching   = _touch_status;
            state.touchPos     = _touch;
            state.buttonsState =
                (_buttons[0] ? ControllerButton.TRIGGER : 0)
                | (_buttons[1] ? ControllerButton.APP : 0)
                | (_buttons[2] ? ControllerButton.HOME : 0);
            state.buttonsDown =
                (_buttons_down[0] ? ControllerButton.TRIGGER : 0)
                | (_buttons_down[1] ? ControllerButton.APP : 0)
                | (_buttons_down[2] ? ControllerButton.HOME : 0);
            state.buttonsUp =
                (_buttons_up[0] ? ControllerButton.TRIGGER : 0)
                | (_buttons_up[1] ? ControllerButton.APP : 0)
                | (_buttons_up[2] ? ControllerButton.HOME : 0);
        }