public void CreateSession(ARCoreSession sessionComponent) { sessionComponent.StartCoroutine(InstantPreviewManager.InitializeIfNeeded()); if (SessionComponent != null) { Debug.LogError("Multiple ARCore session components cannot exist in the scene. " + "Destroying the newest."); GameObject.Destroy(sessionComponent); return; } SessionComponent = sessionComponent; }
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); }
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); }
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); }
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()); }
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); }
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); }
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.LightEstimationMode != LightEstimationMode.Disabled) { InstantPreviewManager.LogLimitedSupportMessage("enable 'Light Estimation'"); config.LightEstimationMode = LightEstimationMode.Disabled; } 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); }
private void _UpdateTextureIfNeeded() { // If running in editor, updates background texture from Instant Preview only. Texture2D previewBackgroundTexture = BackgroundTexture; if (InstantPreviewManager.UpdateBackgroundTextureIfNeeded(ref previewBackgroundTexture)) { BackgroundTexture = previewBackgroundTexture; return; } IntPtr frameHandle = IntPtr.Zero; ExternApi.ArPresto_getFrame(ref frameHandle); int backgroundTextureId = ExternApi.ArCoreUnity_getBackgroundTextureId(); if (frameHandle == IntPtr.Zero) { // This prevents using a texture that has not been filled out by ARCore. return; } else if (backgroundTextureId == -1) { return; } else if (BackgroundTexture != null && BackgroundTexture.GetNativeTexturePtr().ToInt32() == backgroundTextureId) { return; } else if (BackgroundTexture == null) { // The Unity-cached size and format of the texture (0x0, ARGB) is not the // actual format of the texture. This is okay because the texture is not // accessed by pixels, it is accessed with UV coordinates. BackgroundTexture = Texture2D.CreateExternalTexture( 0, 0, TextureFormat.ARGB32, false, false, new IntPtr(backgroundTextureId)); return; } BackgroundTexture.UpdateExternalTexture(new IntPtr(backgroundTextureId)); }
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(m_CheckApkAvailabilityResultCallback, IntPtr.Zero); m_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, m_RequestApkInstallationResultCallback, IntPtr.Zero); m_PendingInstallationRequestCallbacks.Add(onComplete); return(task); }
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); }
private bool _SetCameraDirection(DeviceCameraDirection cameraDirection) { // The camera direction has not changed. if (m_CachedCameraDirection.HasValue && m_CachedCameraDirection.Value == cameraDirection) { return(false); } if (InstantPreviewManager.IsProvidingPlatform && cameraDirection == DeviceCameraDirection.BackFacing) { return(false); } else if (InstantPreviewManager.IsProvidingPlatform) { InstantPreviewManager.LogLimitedSupportMessage( "enable front-facing (selfie) camera"); m_CachedCameraDirection = DeviceCameraDirection.BackFacing; if (SessionComponent != null) { SessionComponent.DeviceCameraDirection = DeviceCameraDirection.BackFacing; } return(false); } m_CachedCameraDirection = cameraDirection; var apiCameraDirection = cameraDirection == DeviceCameraDirection.BackFacing ? ApiPrestoDeviceCameraDirection.BackFacing : ApiPrestoDeviceCameraDirection.FrontFacing; ExternApi.ArPresto_setDeviceCameraDirection(apiCameraDirection); return(true); }
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); }
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); }