public static void UpdateSessionConfig( IntPtr sessionHandle, IntPtr configHandle, ARCoreExtensionsConfig config) { if (config.DepthModeOverride != DepthModeOverride.DoNotOverride) { ApiDepthMode apiDepthMode = config.DepthModeOverride.ToApiDepthMode(); ExternApi.ArConfig_setDepthMode(sessionHandle, configHandle, apiDepthMode); } #if UNITY_ANDROID ApiCloudAnchorMode cloudAnchorMode = (ApiCloudAnchorMode)config.CloudAnchorMode; ExternApi.ArConfig_setCloudAnchorMode( sessionHandle, configHandle, cloudAnchorMode); ApiSegmentationMode segmentationMode = config.SegmentationMode.ToApiSegmentationMode(); ExternApi.ArConfig_setSegmentationMode_private( sessionHandle, configHandle, segmentationMode); #endif if (config.UseHorizontalAndVerticalLowFeatureGrowth) { ExternApi.ArConfig_setPlaneFindingMode( sessionHandle, configHandle, ApiPlaneFindingModes.HorizontalAndVerticalLowFeatureGrowth); } }
/// <summary> /// Wrap an ARCoreSessionConfig in an API config. /// </summary> /// <param name="config">Config to wrap.</param> /// <param name="handle"> /// GCHandle pinning internal IntPtr. The caller is responsible for calling GCHandle.Free /// when done with this config. /// </param> public ApiPrestoConfig(ARCoreSessionConfig config, out GCHandle handle) { UpdateMode = config.MatchCameraFramerate ? ApiUpdateMode.Blocking : ApiUpdateMode.LatestCameraImage; var planeFindingMode = ApiPlaneFindingMode.Disabled; switch (config.PlaneFindingMode) { case DetectedPlaneFindingMode.Horizontal: planeFindingMode = ApiPlaneFindingMode.Horizontal; break; case DetectedPlaneFindingMode.Vertical: planeFindingMode = ApiPlaneFindingMode.Vertical; break; case DetectedPlaneFindingMode.HorizontalAndVertical: planeFindingMode = ApiPlaneFindingMode.HorizontalAndVertical; break; default: break; } PlaneFindingMode = planeFindingMode; LightEstimationMode = config.EnableLightEstimation ? ApiLightEstimationMode.AmbientIntensity : ApiLightEstimationMode.Disabled; CloudAnchorMode = config.EnableCloudAnchor ? ApiCloudAnchorMode.Enabled : ApiCloudAnchorMode.Disabled; if (config.AugmentedImageDatabase != null) { byte[] rawData = config.AugmentedImageDatabase.GetRawData(); handle = GCHandle.Alloc(rawData, GCHandleType.Pinned); AugmentedImageDatabaseBytes = handle.AddrOfPinnedObject(); AugmentedImageDatabaseSize = rawData.Length; } else { handle = new GCHandle(); AugmentedImageDatabaseBytes = IntPtr.Zero; AugmentedImageDatabaseSize = 0; } switch (config.CameraFocusMode) { case GoogleARCore.CameraFocusMode.Fixed: CameraFocusMode = ApiCameraFocusMode.Fixed; break; case GoogleARCore.CameraFocusMode.Auto: CameraFocusMode = ApiCameraFocusMode.Auto; break; default: CameraFocusMode = ApiCameraFocusMode.Fixed; break; } }
public static void UpdateApiConfigWithARCoreSessionConfig(IntPtr sessionHandle, IntPtr configHandle, ARCoreSessionConfig sessionConfig) { ApiLightEstimationMode lightingMode = sessionConfig.LightEstimationMode.ToApiLightEstimationMode(); ExternApi.ArConfig_setLightEstimationMode(sessionHandle, configHandle, lightingMode); ApiPlaneFindingMode planeFindingMode = sessionConfig.PlaneFindingMode.ToApiPlaneFindingMode(); ExternApi.ArConfig_setPlaneFindingMode(sessionHandle, configHandle, planeFindingMode); ApiUpdateMode updateMode = sessionConfig.MatchCameraFramerate ? ApiUpdateMode.Blocking : ApiUpdateMode.LatestCameraImage; ExternApi.ArConfig_setUpdateMode(sessionHandle, configHandle, updateMode); ApiCloudAnchorMode cloudAnchorMode = sessionConfig.CloudAnchorMode.ToApiCloudAnchorMode(); ExternApi.ArConfig_setCloudAnchorMode(sessionHandle, configHandle, cloudAnchorMode); IntPtr augmentedImageDatabaseHandle = IntPtr.Zero; if (sessionConfig.AugmentedImageDatabase != null) { augmentedImageDatabaseHandle = sessionConfig.AugmentedImageDatabase._nativeHandle; ExternApi.ArConfig_setAugmentedImageDatabase(sessionHandle, configHandle, augmentedImageDatabaseHandle); } else { ExternApi.ArConfig_setAugmentedImageDatabase(sessionHandle, configHandle, IntPtr.Zero); } ApiAugmentedFaceMode augmentedFaceMode = sessionConfig.AugmentedFaceMode.ToApiAugmentedFaceMode(); ExternApi.ArConfig_setAugmentedFaceMode(sessionHandle, configHandle, augmentedFaceMode); ApiCameraFocusMode focusMode = sessionConfig.CameraFocusMode.ToApiCameraFocusMode(); ExternApi.ArConfig_setFocusMode(sessionHandle, configHandle, focusMode); if (!InstantPreviewManager.IsProvidingPlatform) { ApiDepthMode depthMode = sessionConfig.DepthMode.ToApiDepthMode(); ExternApi.ArConfig_setDepthMode(sessionHandle, configHandle, depthMode); } if (!InstantPreviewManager.IsProvidingPlatform) { ExternApi.ArConfig_setInstantPlacementMode(sessionHandle, configHandle, sessionConfig.InstantPlacementMode); } }
public static void UpdateSessionConfig( IntPtr sessionHandle, IntPtr configHandle, ARCoreExtensionsConfig config) { #if UNITY_ANDROID ApiCloudAnchorMode cloudAnchorMode = (ApiCloudAnchorMode)config.CloudAnchorMode; ExternApi.ArConfig_setCloudAnchorMode( sessionHandle, configHandle, cloudAnchorMode); #endif // UNITY_ANDROID }
/// <summary> /// Wrap an ARCoreSessionConfig in an API config. /// </summary> /// <param name="config">Config to wrap.</param> public ApiPrestoConfig(ARCoreSessionConfig config) { UpdateMode = config.MatchCameraFramerate ? ApiUpdateMode.Blocking : ApiUpdateMode.LatestCameraImage; var planeFindingMode = ApiPlaneFindingMode.Disabled; switch (config.PlaneFindingMode) { case DetectedPlaneFindingMode.Horizontal: planeFindingMode = ApiPlaneFindingMode.Horizontal; break; case DetectedPlaneFindingMode.Vertical: planeFindingMode = ApiPlaneFindingMode.Vertical; break; case DetectedPlaneFindingMode.HorizontalAndVertical: planeFindingMode = ApiPlaneFindingMode.HorizontalAndVertical; break; default: break; } PlaneFindingMode = planeFindingMode; LightEstimationMode = config.EnableLightEstimation ? ApiLightEstimationMode.AmbientIntensity : ApiLightEstimationMode.Disabled; CloudAnchorMode = config.EnableCloudAnchor ? ApiCloudAnchorMode.Enabled : ApiCloudAnchorMode.Disabled; if (config.AugmentedImageDatabase != null) { ArPrestoAugmentedImageDatabase = config.AugmentedImageDatabase.m_ArPrestoDatabaseHandle; } else { ArPrestoAugmentedImageDatabase = IntPtr.Zero; } switch (config.CameraFocusMode) { case GoogleARCore.CameraFocusMode.Fixed: CameraFocusMode = ApiCameraFocusMode.Fixed; break; case GoogleARCore.CameraFocusMode.Auto: CameraFocusMode = ApiCameraFocusMode.Auto; break; default: CameraFocusMode = ApiCameraFocusMode.Fixed; break; } }
public static void UpdateSessionConfig( IntPtr sessionHandle, IntPtr configHandle, ARCoreExtensionsConfig config) { #if !UNITY_IOS || CLOUDANCHOR_IOS_SUPPORT ApiCloudAnchorMode cloudAnchorMode = (ApiCloudAnchorMode)config.CloudAnchorMode; ExternApi.ArConfig_setCloudAnchorMode(sessionHandle, configHandle, cloudAnchorMode); #endif // CLOUDANCHORS #if !UNITY_IOS || GEOSPATIAL_IOS_SUPPORT ApiGeospatialMode geospatialMode = config.GeospatialMode.ToApiGeospatialMode(); ExternApi.ArConfig_setGeospatialMode(sessionHandle, configHandle, geospatialMode); #endif // EARTH #if UNITY_ANDROID #endif // UNITY_ANDROID }
public static void EnableCloudAnchors( IntPtr sessionHandle, bool enabled) { // Get the config we're using for updates. IntPtr configHandle = _GetArConfig(sessionHandle); if (configHandle == IntPtr.Zero) { return; } // Get the current configuration. ExternApi.ArSession_getConfig(sessionHandle, configHandle); // Check the current mode to see if an update is needed. ApiCloudAnchorMode currentCloudAnchorMode = ApiCloudAnchorMode.Disabled; ExternApi.ArConfig_getCloudAnchorMode( sessionHandle, configHandle, ref currentCloudAnchorMode); // Update the configuration if needed. ApiCloudAnchorMode newCloudAnchorMode = enabled ? ApiCloudAnchorMode.Enabled : ApiCloudAnchorMode.Disabled; if (currentCloudAnchorMode != newCloudAnchorMode) { // Set the new Cloud Anchor mode. ExternApi.ArConfig_setCloudAnchorMode( sessionHandle, configHandle, enabled ? ApiCloudAnchorMode.Enabled : ApiCloudAnchorMode.Disabled); // Configure the session. ApiArStatus status = ExternApi.ArSession_configure( sessionHandle, configHandle); if (status != ApiArStatus.Success) { Debug.LogErrorFormat("Unable to set ARCore configuration for Cloud Anchors, " + "status '{0}'", status); } } }
public static void UpdateApiConfigWithARCoreSessionConfig(IntPtr sessionHandle, IntPtr configHandle, ARCoreSessionConfig sessionConfig) { ApiLightEstimationMode lightingMode = sessionConfig.LightEstimationMode.ToApiLightEstimationMode(); ExternApi.ArConfig_setLightEstimationMode(sessionHandle, configHandle, lightingMode); ApiPlaneFindingMode planeFindingMode = sessionConfig.PlaneFindingMode.ToApiPlaneFindingMode(); ExternApi.ArConfig_setPlaneFindingMode(sessionHandle, configHandle, planeFindingMode); ApiUpdateMode updateMode = sessionConfig.MatchCameraFramerate ? ApiUpdateMode.Blocking : ApiUpdateMode.LatestCameraImage; ExternApi.ArConfig_setUpdateMode(sessionHandle, configHandle, updateMode); ApiCloudAnchorMode cloudAnchorMode = sessionConfig.EnableCloudAnchor ? ApiCloudAnchorMode.Enabled : ApiCloudAnchorMode.Disabled; ExternApi.ArConfig_setCloudAnchorMode(sessionHandle, configHandle, cloudAnchorMode); IntPtr augmentedImageDatabaseHandle = IntPtr.Zero; if (sessionConfig.AugmentedImageDatabase != null) { augmentedImageDatabaseHandle = sessionConfig.AugmentedImageDatabase.NativeHandle; ExternApi.ArConfig_setAugmentedImageDatabase(sessionHandle, configHandle, augmentedImageDatabaseHandle); } ApiAugmentedFaceMode augmentedFaceMode = sessionConfig.AugmentedFaceMode.ToApiAugmentedFaceMode(); ExternApi.ArConfig_setAugmentedFaceMode(sessionHandle, configHandle, augmentedFaceMode); ApiCameraFocusMode focusMode = sessionConfig.CameraFocusMode.ToApiCameraFocusMode(); ExternApi.ArConfig_setFocusMode(sessionHandle, configHandle, focusMode); }
public static extern void ArConfig_getCloudAnchorMode( IntPtr sessionHandle, IntPtr configHandle, ref ApiCloudAnchorMode mode);
public static extern void ArConfig_setCloudAnchorMode( IntPtr session, IntPtr config, ApiCloudAnchorMode cloud_anchor_mode);
/// <summary> /// Wrap an ARCoreSessionConfig in an API config. /// </summary> /// <param name="config">Config to wrap.</param> public ApiPrestoConfig(ARCoreSessionConfig config) { UpdateMode = config.MatchCameraFramerate ? ApiUpdateMode.Blocking : ApiUpdateMode.LatestCameraImage; var planeFindingMode = ApiPlaneFindingMode.Disabled; switch (config.PlaneFindingMode) { case DetectedPlaneFindingMode.Horizontal: planeFindingMode = ApiPlaneFindingMode.Horizontal; break; case DetectedPlaneFindingMode.Vertical: planeFindingMode = ApiPlaneFindingMode.Vertical; break; case DetectedPlaneFindingMode.HorizontalAndVertical: planeFindingMode = ApiPlaneFindingMode.HorizontalAndVertical; break; default: break; } PlaneFindingMode = planeFindingMode; LightEstimationMode = config.EnableLightEstimation ? ApiLightEstimationMode.AmbientIntensity : ApiLightEstimationMode.Disabled; CloudAnchorMode = config.EnableCloudAnchor ? ApiCloudAnchorMode.Enabled : ApiCloudAnchorMode.Disabled; if (config.AugmentedImageDatabase != null) { ArPrestoAugmentedImageDatabase = config.AugmentedImageDatabase.m_ArPrestoDatabaseHandle; } else { ArPrestoAugmentedImageDatabase = IntPtr.Zero; } switch (config.CameraFocusMode) { case GoogleARCore.CameraFocusMode.Fixed: CameraFocusMode = ApiCameraFocusMode.Fixed; break; case GoogleARCore.CameraFocusMode.Auto: #if UNITY_EDITOR CameraFocusMode = ApiCameraFocusMode.Fixed; UnityEngine.Debug.LogWarningFormat( "Camera focus mode '{0}' not supported in editor.\n" + "Using camera focus mode '{1}' instead.", config.CameraFocusMode, CameraFocusMode); #else CameraFocusMode = ApiCameraFocusMode.Auto; #endif break; default: CameraFocusMode = ApiCameraFocusMode.Fixed; break; } }
public static extern ApiArStatus ArSession_setCloudAnchorMode(IntPtr sessionHandle, ApiCloudAnchorMode cloud_anchor_mode);
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; } if (_cachedCloudAnchorMode != ARCoreExtensions._instance.ARCoreExtensionsConfig.CloudAnchorMode) { ApiCloudAnchorMode mode = (ApiCloudAnchorMode) ARCoreExtensions._instance.ARCoreExtensionsConfig.CloudAnchorMode; status = ExternApi.ArSession_setCloudAnchorMode(_sessionHandle, mode); if (status != ApiArStatus.Success) { Debug.LogErrorFormat( "Could not set CloudAnchorMode {0} ({1}).", mode, status); return; } else { Debug.LogFormat("Set Cloud Anchor Mode to {0}.", mode); } _cachedCloudAnchorMode = ARCoreExtensions._instance.ARCoreExtensionsConfig.CloudAnchorMode; } } }