示例#1
0
        private void OnFrameUpdate(ARCameraFrameEventArgs frameEventArgs)
        {
            if (!ShouldUpdateARCoreSession())
            {
                return;
            }

            if (_sessionHandle == IntPtr.Zero)
            {
                return;
            }

            if (_frameHandle != IntPtr.Zero)
            {
                SessionApi.ReleaseFrame(_frameHandle);
                _frameHandle = IntPtr.Zero;
            }

            if (_arKitSession != null && _cameraManager != null && _arKitSession.enabled)
            {
                var cameraParams = new XRCameraParams
                {
                    zNear             = _cameraManager.GetComponent <Camera>().nearClipPlane,
                    zFar              = _cameraManager.GetComponent <Camera>().farClipPlane,
                    screenWidth       = Screen.width,
                    screenHeight      = Screen.height,
                    screenOrientation = Screen.orientation
                };

                if (!_cameraManager.subsystem.TryGetLatestFrame(
                        cameraParams, out XRCameraFrame frame))
                {
                    Debug.LogWarning("XRCamera's latest frame is not available now.");
                    return;
                }

                if (frame.timestampNs == 0 || frame.FrameHandle() == IntPtr.Zero)
                {
                    Debug.LogWarning("ARKit Plugin Frame is not ready.");
                    return;
                }

                var status = ExternApi.ArSession_updateAndAcquireArFrame(
                    _sessionHandle, frame.FrameHandle(), ref _frameHandle);
                if (status != ApiArStatus.Success)
                {
                    Debug.LogErrorFormat("Failed to update and acquire ARFrame with error: " +
                                         "{0}", status);
                    return;
                }
            }
        }
示例#2
0
        public void ResetARCoreSession()
        {
            if (m_SessionHandle != IntPtr.Zero)
            {
                Debug.Log("Reset cross platform ARCoreSession.");
                if (m_FrameHandle != IntPtr.Zero)
                {
                    SessionApi.ReleaseFrame(m_FrameHandle);
                    m_FrameHandle = IntPtr.Zero;
                }

                ExternApi.ArSession_destroy(m_SessionHandle);
                m_SessionHandle = IntPtr.Zero;
            }
        }
示例#3
0
        public static TrackingState GetEarthTrackingState(IntPtr sessionHandle)
        {
            var trackingState = ApiTrackingState.Stopped;

#if !UNITY_IOS || GEOSPATIAL_IOS_SUPPORT
            IntPtr earthHandle = SessionApi.AcquireEarth(sessionHandle);
            if (earthHandle == IntPtr.Zero)
            {
                return(trackingState.ToTrackingState());
            }

            ExternApi.ArTrackable_getTrackingState(sessionHandle, earthHandle, ref trackingState);
            ExternApi.ArTrackable_release(earthHandle);
#endif
            return(trackingState.ToTrackingState());
        }
示例#4
0
        public static EarthState GetEarthState(IntPtr sessionHandle)
        {
            var earthState = EarthState.ErrorInternal;

#if !UNITY_IOS || GEOSPATIAL_IOS_SUPPORT
            IntPtr earthHandle = SessionApi.AcquireEarth(sessionHandle);
            if (earthHandle == IntPtr.Zero)
            {
                return(earthState);
            }

            ExternApi.ArEarth_getEarthState(sessionHandle, earthHandle, ref earthState);
            ExternApi.ArTrackable_release(earthHandle);
#endif
            return(earthState);
        }
示例#5
0
        public static void TryGetCameraGeospatialPose(
            IntPtr sessionHandle, ref GeospatialPose geospatialPose)
        {
#if !UNITY_IOS || GEOSPATIAL_IOS_SUPPORT
            IntPtr earthHandle = SessionApi.AcquireEarth(sessionHandle);
            if (earthHandle == IntPtr.Zero)
            {
                return;
            }

            IntPtr geospatialPoseHandle = GeospatialPoseApi.Create(sessionHandle);
            ExternApi.ArEarth_getCameraGeospatialPose(sessionHandle, earthHandle,
                                                      geospatialPoseHandle);
            GeospatialPoseApi.GetGeospatialPose(
                sessionHandle, geospatialPoseHandle, ref geospatialPose);
            GeospatialPoseApi.Destroy(geospatialPoseHandle);
            ExternApi.ArTrackable_release(earthHandle);
#endif
        }