Пример #1
0
        public bool GetAllCameraMetadataTags(
            IntPtr cameraMetadataHandle, List <CameraMetadataTag> resultList)
        {
            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage("access camera metadata tags");
                return(false);
            }

            IntPtr tagsHandle = IntPtr.Zero;
            int    tagsCount  = 0;

            ExternApi.ArImageMetadata_getAllKeys(
                _nativeSession.SessionHandle, cameraMetadataHandle, ref tagsCount, ref tagsHandle);
            if (tagsCount == 0 || tagsHandle == IntPtr.Zero)
            {
                ARDebug.LogError(
                    "ArImageMetadata_getAllKeys error with empty metadata keys list.");
                return(false);
            }

            for (int i = 0; i < tagsCount; i++)
            {
                resultList.Add((CameraMetadataTag)Marshal.PtrToStructure(
                                   MarshalingHelper.GetPtrToUnmanagedArrayElement <int>(tagsHandle, i),
                                   typeof(int)));
            }

            return(true);
        }
Пример #2
0
        private void _SetConfiguration(ARCoreSessionConfig config)
        {
            // There is no configuration to set.
            if (config == null)
            {
                return;
            }

            // The configuration has not been updated.
            if (m_CachedConfig != null && config.Equals(m_CachedConfig) &&
                (config.AugmentedImageDatabase == null ||
                 !config.AugmentedImageDatabase.m_IsDirty) &&
                !ExperimentManager.Instance.IsConfigurationDirty)
            {
                return;
            }

            if (InstantPreviewManager.IsProvidingPlatform)
            {
                if (config.PlaneFindingMode == DetectedPlaneFindingMode.Disabled)
                {
                    InstantPreviewManager.LogLimitedSupportMessage("disable 'Plane Finding'");
                    config.PlaneFindingMode = DetectedPlaneFindingMode.Horizontal;
                }

                if (!config.EnableLightEstimation)
                {
                    InstantPreviewManager.LogLimitedSupportMessage("disable 'Light Estimation'");
                    config.EnableLightEstimation = true;
                }

                if (config.CameraFocusMode == CameraFocusMode.Auto)
                {
                    InstantPreviewManager.LogLimitedSupportMessage("enable camera Auto Focus mode");
                    config.CameraFocusMode = CameraFocusMode.Fixed;
                }

                if (config.AugmentedImageDatabase != null)
                {
                    InstantPreviewManager.LogLimitedSupportMessage("enable 'Augmented Images'");
                    config.AugmentedImageDatabase = null;
                }

                if (config.AugmentedFaceMode == AugmentedFaceMode.Mesh)
                {
                    InstantPreviewManager.LogLimitedSupportMessage("enable 'Augmented Faces'");
                    config.AugmentedFaceMode = AugmentedFaceMode.Disabled;
                }
            }

            var prestoConfig = new ApiPrestoConfig(config);

            ExternApi.ArPresto_setConfiguration(ref prestoConfig);
            m_CachedConfig = ScriptableObject.CreateInstance <ARCoreSessionConfig>();
            m_CachedConfig.CopyFrom(config);
        }
Пример #3
0
        public IntPtr Create()
        {
            IntPtr cameraConfigHandle = IntPtr.Zero;

            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage("create ARCamera config");
                return(cameraConfigHandle);
            }

            ExternApi.ArCameraConfig_create(m_NativeSession.SessionHandle, ref cameraConfigHandle);
            return(cameraConfigHandle);
        }
        public CameraConfigStereoCameraUsage GetStereoCameraUsage(IntPtr cameraConfigHandle)
        {
            int stereoCameraUsage = (int)CameraConfigStereoCameraUsage.DoNotUse;

            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage("access ARCamera StereoCameraUsage");
                return((CameraConfigStereoCameraUsage)stereoCameraUsage);
            }

            ExternApi.ArCameraConfig_getStereoCameraUsage(_nativeSession.SessionHandle,
                                                          cameraConfigHandle, ref stereoCameraUsage);
            return((CameraConfigStereoCameraUsage)stereoCameraUsage);
        }
Пример #5
0
        public CameraConfigDepthSensorUsages GetDepthSensorUsage(IntPtr cameraConfigHandle)
        {
            int depthSensorUsage = (int)CameraConfigDepthSensorUsages.DoNotUse;

            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage("access ARCamera DepthSensorUsage");
                return((CameraConfigDepthSensorUsages)depthSensorUsage);
            }

            ExternApi.ArCameraConfig_getDepthSensorUsage(
                m_NativeSession.SessionHandle, cameraConfigHandle, ref depthSensorUsage);
            return((CameraConfigDepthSensorUsages)depthSensorUsage);
        }
Пример #6
0
        public void GetImageDimensions(IntPtr cameraConfigHandle, out int width, out int height)
        {
            width  = 0;
            height = 0;

            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage("access ARCamera image dimensions");
                return;
            }

            ExternApi.ArCameraConfig_getImageDimensions(
                m_NativeSession.SessionHandle, cameraConfigHandle, ref width, ref height);
        }
Пример #7
0
        public void GetFpsRange(IntPtr cameraConfigHandle, out int minFps, out int maxFps)
        {
            minFps = 0;
            maxFps = 0;

            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage("access ARCamera FpsRange");
                return;
            }

            ExternApi.ArCameraConfig_getFpsRange(
                m_NativeSession.SessionHandle, cameraConfigHandle, ref minFps, ref maxFps);
        }
Пример #8
0
        public int AddAugmentedImageAtRuntime(IntPtr augmentedImageDatabaseHandle, string name,
                                              AugmentedImageSrc imageSrc, float width)
        {
            int outIndex = -1;

            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage(
                    "add images to Augmented Image database");
                return(outIndex);
            }

            GCHandle grayscaleBytesHandle = _ConvertTextureToGrayscaleBytes(imageSrc);

            if (grayscaleBytesHandle.AddrOfPinnedObject() == IntPtr.Zero)
            {
                return(-1);
            }

            ApiArStatus status;

            if (width > 0)
            {
                status = ExternApi.ArAugmentedImageDatabase_addImageWithPhysicalSize(
                    m_NativeSession.SessionHandle, augmentedImageDatabaseHandle, name,
                    grayscaleBytesHandle.AddrOfPinnedObject(), imageSrc.Width,
                    imageSrc.Height, imageSrc.Width, width, ref outIndex);
            }
            else
            {
                status = ExternApi.ArAugmentedImageDatabase_addImage(
                    m_NativeSession.SessionHandle, augmentedImageDatabaseHandle, name,
                    grayscaleBytesHandle.AddrOfPinnedObject(), imageSrc.Width,
                    imageSrc.Height, imageSrc.Width, ref outIndex);
            }

            if (grayscaleBytesHandle.IsAllocated)
            {
                grayscaleBytesHandle.Free();
            }

            if (status != ApiArStatus.Success)
            {
                Debug.LogWarningFormat(
                    "Failed to add aumented image at runtime with status {0}", status);
                return(-1);
            }

            return(outIndex);
        }
Пример #9
0
        public LostTrackingReason GetLostTrackingReason(IntPtr cameraHandle)
        {
            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage("determine tracking failure " +
                                                               "reasons");
                return(LostTrackingReason.None);
            }

            ApiTrackingFailureReason apiTrackingFailureReason = ApiTrackingFailureReason.None;

            ExternApi.ArCamera_getTrackingFailureReason(m_NativeSession.SessionHandle,
                                                        cameraHandle, ref apiTrackingFailureReason);
            return(apiTrackingFailureReason.ToLostTrackingReason());
        }
Пример #10
0
        public ApiCameraConfigFacingDirection GetFacingDirection(IntPtr cameraConfigHandle)
        {
            ApiCameraConfigFacingDirection direction = ApiCameraConfigFacingDirection.Back;

            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage("access ARCamera facing direction");
                return(direction);
            }

            ExternApi.ArCameraConfig_getFacingDirection(
                m_NativeSession.SessionHandle, cameraConfigHandle, ref direction);

            return(direction);
        }
Пример #11
0
        public CameraConfig GetCameraConfig()
        {
            IntPtr cameraConfigHandle = m_NativeSession.CameraConfigApi.Create();

            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage("access camera config");
                return(new CameraConfig());
            }

            ExternApi.ArSession_getCameraConfig(m_NativeSession.SessionHandle, cameraConfigHandle);
            CameraConfig currentCameraConfig = _CreateCameraConfig(cameraConfigHandle);

            m_NativeSession.CameraConfigApi.Destroy(cameraConfigHandle);
            return(currentCameraConfig);
        }
        public AsyncTask <ApkAvailabilityStatus> CheckApkAvailability()
        {
            Action <ApkAvailabilityStatus>    onComplete;
            AsyncTask <ApkAvailabilityStatus> task =
                new AsyncTask <ApkAvailabilityStatus>(out onComplete);

            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage("determine ARCore APK " +
                                                               "availability");
                return(task);
            }

            ExternApi.ArPresto_checkApkAvailability(_checkApkAvailabilityResultCallback,
                                                    IntPtr.Zero);

            _pendingAvailabilityCheckCallbacks.Add(onComplete);

            return(task);
        }
        public AsyncTask <ApkInstallationStatus> RequestApkInstallation(bool userRequested)
        {
            Action <ApkInstallationStatus>    onComplete;
            AsyncTask <ApkInstallationStatus> task =
                new AsyncTask <ApkInstallationStatus>(out onComplete);

            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage("request installation of ARCore " +
                                                               "APK");
                return(task);
            }

            ExternApi.ArPresto_requestApkInstallation(userRequested,
                                                      _requestApkInstallationResultCallback, IntPtr.Zero);

            _pendingInstallationRequestCallbacks.Add(onComplete);

            return(task);
        }
Пример #14
0
        private void _SetCameraDirection(DeviceCameraDirection cameraDirection)
        {
            // The camera direction has not changed.
            if (m_CachedCameraDirection.HasValue && m_CachedCameraDirection.Value == cameraDirection)
            {
                return;
            }

            if (InstantPreviewManager.IsProvidingPlatform && cameraDirection == DeviceCameraDirection.BackFacing)
            {
                return;
            }
            else if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage("enable front-facing (selfie) camera");
                m_CachedCameraDirection = DeviceCameraDirection.BackFacing;
                if (SessionComponent != null)
                {
                    SessionComponent.DeviceCameraDirection = DeviceCameraDirection.BackFacing;
                }

                return;
            }

            if (OnSessionSetEnabled != null)
            {
                OnSessionSetEnabled(false);
            }

            var apiCameraDirection = cameraDirection == DeviceCameraDirection.BackFacing ?
                                     ApiPrestoDeviceCameraDirection.BackFacing : ApiPrestoDeviceCameraDirection.FrontFacing;

            ExternApi.ArPresto_setDeviceCameraDirection(apiCameraDirection);
            m_CachedCameraDirection = cameraDirection;

            if (OnSessionSetEnabled != null)
            {
                OnSessionSetEnabled(true);
            }
        }
        private bool SetCameraDirection(DeviceCameraDirection cameraDirection)
        {
            // The camera direction has not changed.
            if (_cachedCameraDirection.HasValue &&
                _cachedCameraDirection.Value == cameraDirection)
            {
                return(false);
            }

            if (InstantPreviewManager.IsProvidingPlatform &&
                cameraDirection == DeviceCameraDirection.BackFacing)
            {
                return(false);
            }
            else if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage(
                    "enable front-facing (selfie) camera");
                _cachedCameraDirection = DeviceCameraDirection.BackFacing;
                if (SessionComponent != null)
                {
                    SessionComponent.DeviceCameraDirection = DeviceCameraDirection.BackFacing;
                }

                return(false);
            }

            _cachedCameraDirection = cameraDirection;
            ApiPrestoStatus prestoStatus = ApiPrestoStatus.Uninitialized;

            ExternApi.ArPresto_getStatus(ref prestoStatus);
            if (prestoStatus == ApiPrestoStatus.ErrorInvalidCameraConfig)
            {
                // if the session is paused by invalid camera configuration,
                // attempt to recover by changing the camera direction:
                OnBeforeResumeSession(_cachedSessionHandle);
            }

            return(true);
        }
Пример #16
0
        public CameraIntrinsics GetTextureIntrinsics(IntPtr cameraHandle)
        {
            IntPtr cameraIntrinsicsHandle = IntPtr.Zero;

            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage("access GPU texture intrinsics");
                return(new CameraIntrinsics());
            }

            ExternApi.ArCameraIntrinsics_create(
                m_NativeSession.SessionHandle, ref cameraIntrinsicsHandle);

            ExternApi.ArCamera_getTextureIntrinsics(
                m_NativeSession.SessionHandle, cameraHandle, cameraIntrinsicsHandle);

            CameraIntrinsics textureIntrinsics =
                _GetCameraIntrinsicsFromHandle(cameraIntrinsicsHandle);

            ExternApi.ArCameraIntrinsics_destroy(cameraIntrinsicsHandle);

            return(textureIntrinsics);
        }
Пример #17
0
        public Int32 AddImageAtRuntime(
            IntPtr databaseHandle, string name, Texture2D image, float width)
        {
            Int32 outIndex = -1;

            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage("add images to Augmented Image " +
                                                               "database");
                return(outIndex);
            }

            GCHandle grayscaleBytesHandle = _ConvertTextureToGrayscaleBytes(image);

            if (grayscaleBytesHandle.AddrOfPinnedObject() == IntPtr.Zero)
            {
                return(-1);
            }

            ApiArStatus status = ExternApi.ArPrestoAugmentedImageDatabase_addImageAtRuntime(
                databaseHandle, name, grayscaleBytesHandle.AddrOfPinnedObject(), image.width,
                image.height, image.width, width, ref outIndex);

            if (grayscaleBytesHandle.IsAllocated)
            {
                grayscaleBytesHandle.Free();
            }

            if (status != ApiArStatus.Success)
            {
                Debug.LogWarningFormat(
                    "Failed to add aumented image at runtime with status {0}", status);
                return(-1);
            }

            return(outIndex);
        }
Пример #18
0
        public bool GetAllCameraMetadataTags(
            IntPtr cameraMetadataHandle, List <CameraMetadataTag> resultList)
        {
            IntPtr ndkMetadataHandle = IntPtr.Zero;

            if (InstantPreviewManager.IsProvidingPlatform)
            {
                InstantPreviewManager.LogLimitedSupportMessage("access camera metadata tags");
                return(false);
            }

            ExternApi.ArImageMetadata_getNdkCameraMetadata(m_NativeSession.SessionHandle,
                                                           cameraMetadataHandle, ref ndkMetadataHandle);

            IntPtr          tagsHandle = IntPtr.Zero;
            int             tagsCount  = 0;
            NdkCameraStatus status     = ExternApi.ACameraMetadata_getAllTags(
                ndkMetadataHandle, ref tagsCount, ref tagsHandle);

            if (status != NdkCameraStatus.Ok)
            {
                ARDebug.LogErrorFormat(
                    "ACameraMetadata_getAllTags error with native camera error code: {0}",
                    status);
                return(false);
            }

            for (int i = 0; i < tagsCount; i++)
            {
                resultList.Add((CameraMetadataTag)Marshal.PtrToStructure(
                                   MarshalingHelper.GetPtrToUnmanagedArrayElement <int>(tagsHandle, i),
                                   typeof(int)));
            }

            return(true);
        }