private void _OnARKitFrameUpdated(UnityEngine.XR.iOS.UnityARCamera camera) { if (m_FrameHandle != IntPtr.Zero) { NativeSession.FrameApi.Release(m_FrameHandle); m_FrameHandle = IntPtr.Zero; } if (m_SessionEnabled) { m_FrameHandle = ExternApi.ARCoreARKitIntegration_getCurrentFrame(m_RealArKitSessionHandle); ExternApi.ArSession_updateAndAcquireArFrame( m_SessionHandle, m_FrameHandle, ref m_FrameHandle); } if (NativeSession != null) { NativeSession.OnUpdate(m_FrameHandle); } if (EarlyUpdate != null) { EarlyUpdate(); } }
private void _OnARKitFrameUpdated(UnityEngine.XR.iOS.UnityARCamera camera) { if (_frameHandle != IntPtr.Zero) { NativeSession.FrameApi.Release(_frameHandle); _frameHandle = IntPtr.Zero; } if (_sessionEnabled) { _frameHandle = _arCoreiOSHelper.GetARKitFramePtr(_realArKitSessionHandle); ExternApi.ArSession_updateAndAcquireArFrame( _sessionHandle, _frameHandle, ref _frameHandle); } if (NativeSession != null) { NativeSession.OnUpdate(_frameHandle); } if (EarlyUpdate != null) { EarlyUpdate(); } }
private void _OnEarlyUpdate() { // Update session activity before EarlyUpdate. if (m_CachedSessionEnabled.HasValue) { _SetSessionEnabled(m_CachedSessionEnabled.Value); m_CachedSessionEnabled = null; } // Perform updates before calling ArPresto_update. _UpdateDisplayGeometry(); if (SessionComponent != null) { _SetCameraDirection(SessionComponent.DeviceCameraDirection); _SetConfiguration(SessionComponent.SessionConfig); } // Update ArPresto and potentially ArCore. ExternApi.ArPresto_update(); // Get state information from ARPresto. ApiPrestoStatus prestoStatus = ApiPrestoStatus.Uninitialized; ExternApi.ArPresto_getStatus(ref prestoStatus); SessionStatus = prestoStatus.ToSessionStatus(); LostTrackingReason = LostTrackingReason.None; if (NativeSession != null && SessionStatus == SessionStatus.LostTracking) { var cameraHandle = NativeSession.FrameApi.AcquireCamera(); LostTrackingReason = NativeSession.CameraApi.GetLostTrackingReason(cameraHandle); NativeSession.CameraApi.Release(cameraHandle); } // Get the current session from presto and note if it has changed. IntPtr sessionHandle = IntPtr.Zero; ExternApi.ArPresto_getSession(ref sessionHandle); IsSessionChangedThisFrame = m_CachedSessionHandle != sessionHandle; m_CachedSessionHandle = sessionHandle; ExternApi.ArPresto_getFrame(ref m_CachedFrameHandle); // Update the native session with the newest frame. if (NativeSession != null) { NativeSession.OnUpdate(m_CachedFrameHandle); } _UpdateTextureIfNeeded(); if (EarlyUpdate != null) { EarlyUpdate(); } }
internal void EarlyUpdate() { // Get the latest session handle from presto. IntPtr sessionHandle = IntPtr.Zero; ExternApi.ArPresto_getSession(ref sessionHandle); // Update the display geometry if there is a non-null session. if (sessionHandle != IntPtr.Zero) { _SetDisplayGeometry(sessionHandle, Screen.orientation, Screen.width, Screen.height); } // Update ArPresto and potentially ArCore. ExternApi.ArPresto_update(); // Update pending AsyncTasks. AsyncTask.OnUpdate(); // Update the lifecycle state. _UpdateState(); // Return if there is no session component in the scene. if (SessionComponent == null) { return; } ExternApi.ArPresto_getSession(ref sessionHandle); IntPtr frameHandle = IntPtr.Zero; ExternApi.ArPresto_getFrame(ref frameHandle); if (NativeSession == null && sessionHandle != IntPtr.Zero) { NativeSession = new NativeSession(sessionHandle, frameHandle); NativeSession.SessionApi.ReportEngineType(); } if (NativeSession != null) { NativeSession.OnUpdate(frameHandle); } SetConfiguration(SessionComponent.SessionConfig); _UpdateTextureIfNeeded(); InstantPreviewManager.OnEarlyUpdate(); if (EarlyUpdateEvent != null) { EarlyUpdateEvent(); } }
private void _OnEarlyUpdate() { // Perform updates before calling ArPresto_update. _UpdateDisplayGeometry(); if (SessionComponent != null) { _SetConfiguration(SessionComponent.SessionConfig); } // Update ArPresto and potentially ArCore. ExternApi.ArPresto_update(); // Get state information from ARPresto. ApiPrestoStatus prestoStatus = ApiPrestoStatus.Uninitialized; IntPtr sessionHandle = IntPtr.Zero; IntPtr frameHandle = IntPtr.Zero; ExternApi.ArPresto_getStatus(ref prestoStatus); ExternApi.ArPresto_getSession(ref sessionHandle); ExternApi.ArPresto_getFrame(ref frameHandle); SessionStatus = prestoStatus.ToSessionStatus(); // Update native session reference to match presto. if (sessionHandle == IntPtr.Zero) { NativeSession = null; } else if (NativeSession == null) { NativeSession = new NativeSession(sessionHandle, frameHandle); } // Update the native session with the newest frame. if (NativeSession != null) { NativeSession.OnUpdate(frameHandle); } _UpdateTextureIfNeeded(); if (EarlyUpdate != null) { EarlyUpdate(); } }
private void _OnEarlyUpdate() { _SetCameraTextureName(); // Update session activity before EarlyUpdate. if (m_HaveDisableToEnableTransition) { _SetSessionEnabled(false); _SetSessionEnabled(true); m_HaveDisableToEnableTransition = false; // Avoid firing session enable event twice. if (m_DesiredSessionState.HasValue && m_DesiredSessionState.Value) { m_DesiredSessionState = null; } } if (m_DesiredSessionState.HasValue) { _SetSessionEnabled(m_DesiredSessionState.Value); m_DesiredSessionState = null; } // Perform updates before calling ArPresto_update. if (SessionComponent != null) { IntPtr previousSession = IntPtr.Zero; ExternApi.ArPresto_getSession(ref previousSession); if (UpdateSessionFeatures != null) { UpdateSessionFeatures(); } _SetCameraDirection(SessionComponent.DeviceCameraDirection); IntPtr currentSession = IntPtr.Zero; ExternApi.ArPresto_getSession(ref currentSession); // Fire the session enabled event when the underlying session has been changed // due to session feature update(camera direction etc). if (previousSession != currentSession) { _FireOnSessionSetEnabled(false); _FireOnSessionSetEnabled(true); } // Validate and convert the SessionConfig to a Instant Preview supported config by // logging and disabling limited supported features. if (InstantPreviewManager.IsProvidingPlatform && SessionComponent.SessionConfig != null && !InstantPreviewManager.ValidateSessionConfig(SessionComponent.SessionConfig)) { // A new SessionConfig object will be created based on the original // SessionConfig with all limited support features disabled. SessionComponent.SessionConfig = InstantPreviewManager.GenerateInstantPreviewSupportedConfig( SessionComponent.SessionConfig); } _UpdateConfiguration(SessionComponent.SessionConfig); } _UpdateDisplayGeometry(); // Update ArPresto and potentially ArCore. ExternApi.ArPresto_update(); if (SystemInfo.graphicsMultiThreaded && !InstantPreviewManager.IsProvidingPlatform) { // Synchronize render thread with update call. ExternApi.ARCoreRenderingUtils_CreatePostUpdateFence(); } SessionStatus previousSessionStatus = SessionStatus; // Get state information from ARPresto. ApiPrestoStatus prestoStatus = ApiPrestoStatus.Uninitialized; ExternApi.ArPresto_getStatus(ref prestoStatus); SessionStatus = prestoStatus.ToSessionStatus(); LostTrackingReason = LostTrackingReason.None; if (NativeSession != null && SessionStatus == SessionStatus.LostTracking) { var cameraHandle = NativeSession.FrameApi.AcquireCamera(); LostTrackingReason = NativeSession.CameraApi.GetLostTrackingReason(cameraHandle); NativeSession.CameraApi.Release(cameraHandle); } // If the current status is an error, check if the SessionStatus error state changed. if (SessionStatus.IsError() && previousSessionStatus.IsError() != SessionStatus.IsError()) { // Disable internal session bits so we properly pause the session due to error. _FireOnSessionSetEnabled(false); m_DisabledSessionOnErrorState = true; } else if (SessionStatus.IsValid() && m_DisabledSessionOnErrorState) { if (SessionComponent.enabled) { _FireOnSessionSetEnabled(true); } m_DisabledSessionOnErrorState = false; } // Get the current session from presto and note if it has changed. IntPtr sessionHandle = IntPtr.Zero; ExternApi.ArPresto_getSession(ref sessionHandle); IsSessionChangedThisFrame = m_CachedSessionHandle != sessionHandle; m_CachedSessionHandle = sessionHandle; ExternApi.ArPresto_getFrame(ref m_CachedFrameHandle); // Update the native session with the newest frame. if (NativeSession != null) { NativeSession.OnUpdate(m_CachedFrameHandle); } _UpdateTextureIfNeeded(); if (EarlyUpdate != null) { EarlyUpdate(); } }
private void _OnEarlyUpdate() { // Update session activity before EarlyUpdate. if (m_HaveDisableToEnableTransition) { _SetSessionEnabled(false); _SetSessionEnabled(true); m_HaveDisableToEnableTransition = false; // Avoid firing session enable event twice. if (m_DesiredSessionState.HasValue && m_DesiredSessionState.Value) { m_DesiredSessionState = null; } } if (m_DesiredSessionState.HasValue) { _SetSessionEnabled(m_DesiredSessionState.Value); m_DesiredSessionState = null; } // Perform updates before calling ArPresto_update. if (SessionComponent != null) { IntPtr previousSession = IntPtr.Zero; ExternApi.ArPresto_getSession(ref previousSession); if (UpdateSessionFeatures != null) { UpdateSessionFeatures(); } _SetCameraDirection(SessionComponent.DeviceCameraDirection); IntPtr currentSession = IntPtr.Zero; ExternApi.ArPresto_getSession(ref currentSession); // Fire the session enabled event when the underlying session has been changed // due to session feature update(camera direction etc). if (previousSession != currentSession) { _FireOnSessionSetEnabled(false); _FireOnSessionSetEnabled(true); } _SetConfiguration(SessionComponent.SessionConfig); } _UpdateDisplayGeometry(); // Update ArPresto and potentially ArCore. ExternApi.ArPresto_update(); SessionStatus previousSessionStatus = SessionStatus; // Get state information from ARPresto. ApiPrestoStatus prestoStatus = ApiPrestoStatus.Uninitialized; ExternApi.ArPresto_getStatus(ref prestoStatus); SessionStatus = prestoStatus.ToSessionStatus(); LostTrackingReason = LostTrackingReason.None; if (NativeSession != null && SessionStatus == SessionStatus.LostTracking) { var cameraHandle = NativeSession.FrameApi.AcquireCamera(); LostTrackingReason = NativeSession.CameraApi.GetLostTrackingReason(cameraHandle); NativeSession.CameraApi.Release(cameraHandle); } // If the current status is an error, check if the SessionStatus error state changed. if (SessionStatus.IsError() && previousSessionStatus.IsError() != SessionStatus.IsError()) { // Disable internal session bits so we properly pause the session due to error. _FireOnSessionSetEnabled(false); m_DisabledSessionOnErrorState = true; } else if (SessionStatus.IsValid() && m_DisabledSessionOnErrorState) { if (SessionComponent.enabled) { _FireOnSessionSetEnabled(true); } m_DisabledSessionOnErrorState = false; } // Get the current session from presto and note if it has changed. IntPtr sessionHandle = IntPtr.Zero; ExternApi.ArPresto_getSession(ref sessionHandle); IsSessionChangedThisFrame = m_CachedSessionHandle != sessionHandle; m_CachedSessionHandle = sessionHandle; ExternApi.ArPresto_getFrame(ref m_CachedFrameHandle); // Update the native session with the newest frame. if (NativeSession != null) { NativeSession.OnUpdate(m_CachedFrameHandle); } _UpdateTextureIfNeeded(); if (EarlyUpdate != null) { EarlyUpdate(); } }