Beispiel #1
0
        public void ResetARCoreSession()
        {
            if (_sessionHandle != IntPtr.Zero)
            {
                Debug.Log("Reset cross platform ARCoreSession.");
                if (_frameHandle != IntPtr.Zero)
                {
                    FrameApi.ReleaseFrame(_frameHandle);
                    _frameHandle = IntPtr.Zero;
                }

                ExternApi.ArSession_destroy(_sessionHandle);
                _sessionHandle = IntPtr.Zero;
            }
        }
Beispiel #2
0
        private void OnFrameUpdate(ARCameraFrameEventArgs frameEventArgs)
        {
            if (!_isEnabled)
            {
                return;
            }

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

            if (_frameHandle != IntPtr.Zero)
            {
                FrameApi.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;
                }

                // Update session configuration.
                if (ARCoreExtensions._instance.ARCoreExtensionsConfig != null &&
                    !ARCoreExtensions._instance.ARCoreExtensionsConfig.Equals(_cachedConfig))
                {
                    _cachedConfig = ScriptableObject.CreateInstance <ARCoreExtensionsConfig>();
                    _cachedConfig.CopyFrom(ARCoreExtensions._instance.ARCoreExtensionsConfig);
                    ConfigApi.ConfigureSession(_sessionHandle, _cachedConfig);
                }
            }
        }