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); } }
private static void CheckCompatibilityWithAllSessionConfigs( ARCoreExtensionsProjectSettings settings, Dictionary <ARCoreExtensionsConfig, string> sessionToSceneMap, UnityEditor.BuildTarget buildTarget) { List <IDependentModule> featureModules = DependentModulesManager.GetModules(); foreach (IDependentModule module in featureModules) { ModuleNecessity moduleNecessity = ModuleNecessity.NotRequired; foreach (var entry in sessionToSceneMap) { ARCoreExtensionsConfig sessionConfig = entry.Key; if (!module.IsCompatible(settings, sessionConfig, buildTarget)) { throw new BuildFailedException( string.Format( "{0} isn't compatible with the ARCoreExtensionsConfig in {1}.", module.GetType().Name, entry.Value)); } moduleNecessity = (ModuleNecessity)Math.Max( (int)moduleNecessity, (int)module.GetModuleNecessity(sessionConfig)); } if (moduleNecessity == ModuleNecessity.NotRequired && module.IsEnabled(settings, buildTarget)) { Debug.LogWarning(module.GetEnabledNotRequiredWarning(settings, buildTarget)); } } }
/// <summary> /// Checking whether this module is required with given ARCoreExtensionsConfig. /// In CompatibilityCheckPreprocessBuild, it would loop all explicit sessionConfigs /// via this funcion. If no session configs require this module but this module is /// still enabled, then a warning returned by <see ref="GetEnabledNotRequiredWarning()"/> /// will be logged. /// </summary> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <returns> /// Whether the module is Required/NotRequired/Optional by the sessionConfig. /// </returns> public override ModuleNecessity GetModuleNecessity(ARCoreExtensionsConfig sessionConfig) { if (UseLocation(sessionConfig)) { return(ModuleNecessity.Required); } return(ModuleNecessity.NotRequired); }
/// <summary> /// Checks if the location module should be used if any dependent feature is enabled. /// </summary> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <returns>True if location should be used; otherwise, return false.</returns> private static bool UseLocation(ARCoreExtensionsConfig sessionConfig) { if (sessionConfig.GeospatialMode != GeospatialMode.Disabled) { return(true); } return(false); }
/// <summary> /// Checking whether this module is required with given ARCoreExtensionsConfig. /// In CompatibilityCheckPreprocessBuild, it would loop all explicit sessionConfigs /// via this funcion. If no session configs require this module but this module is /// still enabled, then a warning returned by <see ref="GetEnabledNotRequiredWarning()"/> /// will be logged. /// </summary> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <returns> /// Whether the module is Required/NotRequired/Optional by the sessionConfig. /// </returns> public override ModuleNecessity GetModuleNecessity(ARCoreExtensionsConfig sessionConfig) { if (sessionConfig.CloudAnchorMode != CloudAnchorMode.Disabled) { return(ModuleNecessity.Required); } return(ModuleNecessity.NotRequired); }
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> /// Get the permissions required by this module during the runtime. /// </summary> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <returns> /// The array containing the Runtime Permissions’ names required by this module. /// </returns> public override string[] GetRuntimePermissions(ARCoreExtensionsConfig sessionConfig) { if (UseLocation(sessionConfig)) { return(new string[] { "android.permission.ACCESS_FINE_LOCATION", }); } return(Array.Empty <string>()); }
/// <summary> /// Checking whether this module is compatible with given ARCoreExtensionsConfig and /// ARCoreExtensionsProjectSettings. If it returns false, the /// CompatibilityCheckPreprocessBuild will throw a general Build Failure Error. /// A feature developer should use this function to log detailed error messages that /// also include a recommendation of how to resolve the issue. Note: This method is /// called once per session config. Do not log any warning or info messages here to /// avoid duplicated and/or conflicted information. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns>The boolean shows whether the ARCoreExtensionsProjectSettings is compatible /// with the ARCoreExtensionsConfig.</returns> public virtual bool IsCompatible( ARCoreExtensionsProjectSettings settings, ARCoreExtensionsConfig sessionConfig, UnityEditor.BuildTarget buildTarget) { if (GetModuleNecessity(sessionConfig) == ModuleNecessity.Required && !IsEnabled(settings, buildTarget)) { Debug.LogErrorFormat("{0} is required but not enabled.", this.GetType().Name); return(false); } return(true); }
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 ConfigureSession(IntPtr sessionHandle, ARCoreExtensionsConfig config) { IntPtr configHandle = IntPtr.Zero; ExternApi.ArConfig_create(sessionHandle, ref configHandle); UpdateSessionConfig(sessionHandle, configHandle, config); ApiArStatus status = ExternApi.ArSession_configure(sessionHandle, configHandle); if (status != ApiArStatus.Success) { Debug.LogErrorFormat("Failed to configure the session with error: {0}.", status); } ExternApi.ArConfig_destroy(configHandle); }
/// <summary> /// Checking whether this module is compatible with given ARCoreExtensionsConfig and /// ARCoreExtensionsProjectSettings. If it returns false, the /// CompatibilityCheckPreprocessBuild will throw a general Build Failure Error. /// A feature developer should use this function to log detailed error messages that /// also include a recommendation of how to resolve the issue. Note: This method is /// called once per session config. Do not log any warning or info messages here to /// avoid duplicated and/or conflicted information. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns>The boolean shows whether the ARCoreExtensionsProjectSettings is compatible /// with the ARCoreExtensionsConfig.</returns> public override bool IsCompatible( ARCoreExtensionsProjectSettings settings, ARCoreExtensionsConfig sessionConfig, UnityEditor.BuildTarget buildTarget) { string optionFeaturesSettings = "Edit > Project Settings > XR > ARCore Extensions > Optional Features"; if (sessionConfig.GeospatialMode != GeospatialMode.Disabled && !settings.GeospatialEnabled) { Debug.LogErrorFormat( "LocationModule is required by GeospatialMode {0}. " + "Navigate to {1} and select Geospatial.", sessionConfig.GeospatialMode, optionFeaturesSettings); return(false); } return(true); }
/// <summary> /// Checking whether location module is compatible with given Project Settings. /// If it returns false, the preprocessbuild will throw a general Build Failure Error /// with detailed error messages. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <returns>The boolean shows whether the ARCoreExtensionsProjectSettings is compatible /// with the ARCoreExtensionsConfig.</returns> public override bool IsCompatibleWithSessionConfig(ARCoreExtensionsProjectSettings settings, ARCoreExtensionsConfig sessionConfig) { CloudAnchorMode cloudAnchorMode = sessionConfig.CloudAnchorMode; bool isRequired = cloudAnchorMode == CloudAnchorMode.EnabledWithEarthLocalization; if (isRequired && !IsEnabled(settings)) { Debug.LogErrorFormat( "LocationModule is required by CloudAnchorMode {0}. Navigate to " + "'Project Settings > XR > ARCore Extensions' and select " + "Earth Cloud Anchor Enabled.", cloudAnchorMode); return(false); } else { return(true); } }
/// <summary> /// Checking whether this module is compatible with given ARCoreExtensionsConfig and /// ARCoreExtensionsProjectSettings. If it returns false, the /// CompatibilityCheckPreprocessBuild will throw a general Build Failure Error. /// A feature developer should use this function to log detailed error messages that /// also include a recommendation of how to resolve the issue. Note: This method is /// called once per session config. Do not log any warning or info messages here to /// avoid duplicated and/or conflicted information. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns>The boolean shows whether the ARCoreExtensionsProjectSettings is compatible /// with the ARCoreExtensionsConfig.</returns> public override bool IsCompatible( ARCoreExtensionsProjectSettings settings, ARCoreExtensionsConfig sessionConfig, UnityEditor.BuildTarget buildTarget) { if (buildTarget == UnityEditor.BuildTarget.iOS) { if (sessionConfig.CloudAnchorMode == CloudAnchorMode.Enabled && settings.IOSAuthenticationStrategySetting == IOSAuthenticationStrategy.DoNotUse) { Debug.LogErrorFormat( "Cloud Anchor authentication is required by CloudAnchorMode {0}. " + "An iOS Authentication Strategy must be set in " + "Edit > Project Settings > XR > ARCore Extensions > " + "iOS Authentication Strategy when CloudAnchorMode is {0}", sessionConfig.CloudAnchorMode); return(false); } return(true); } else { if (sessionConfig.CloudAnchorMode == CloudAnchorMode.Enabled && settings.AndroidAuthenticationStrategySetting == AndroidAuthenticationStrategy.DoNotUse) { Debug.LogErrorFormat( "Cloud Anchor authentication is required by CloudAnchorMode {0}. " + "An Android Authentication Strategy must be set in " + "Edit > Project Settings > XR > ARCore Extensions > " + "Android Authentication Strategy when CloudAnchorMode is {0}.", sessionConfig.CloudAnchorMode); return(false); } return(true); } }
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); } } }
/// <summary> /// Checking whether this module is required with given ARCoreExtensionsConfig. /// In CompatibilityCheckPreprocessBuild, it would loop all explicit sessionConfigs /// via this funcion. If no session configs require this module but this module is /// still enabled, then a warning returned by <see ref="GetEnabledNotRequiredWarning()"/> /// will be logged. /// </summary> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <returns> /// Whether the module is Required/NotRequired/Optional by the sessionConfig. /// </returns> public virtual ModuleNecessity GetModuleNecessity(ARCoreExtensionsConfig sessionConfig) { return(ModuleNecessity.NotRequired); }
/// <summary> /// Get the permissions required by this module during the runtime. /// </summary> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <returns> /// The array containing the Runtime Permissions’ names required by this module. /// </returns> public virtual string[] GetRuntimePermissions(ARCoreExtensionsConfig sessionConfig) { return(Array.Empty <string>()); }
/// <summary> /// Checking whether this module is compatible with given ARCoreExtensionsConfig. /// If it returns false, the preprocessbuild will throw a general Build Failure Error. /// A feature developer should use this function to log detailed error messages that /// also include a recommendation of how to resolve the issue. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <returns>The boolean shows whether the ARCoreExtensionsProjectSettings is compatible /// with the ARCoreExtensionsConfig.</returns> public virtual bool IsCompatibleWithSessionConfig( ARCoreExtensionsProjectSettings settings, ARCoreExtensionsConfig sessionConfig) { return(true); }
/// <summary> /// Checking whether this module is compatible with given ARCoreExtensionsConfig and /// ARCoreExtensionsProjectSettings. If it returns false, the /// CompatibilityCheckPreprocessBuild will throw a general Build Failure Error. /// A feature developer should use this function to log detailed error messages that /// also include a recommendation of how to resolve the issue. Note: This method is /// called once per session config. Do not log any warning or info messages here to /// avoid duplicated and/or conflicted information. /// </summary> /// <param name="settings">ARCore Extensions Project Settings.</param> /// <param name="sessionConfig">ARCore Extensions Config.</param> /// <param name="buildTarget">Target build platform.</param> /// <returns>The boolean shows whether the ARCoreExtensionsProjectSettings is compatible /// with the ARCoreExtensionsConfig.</returns> public override bool IsCompatible( ARCoreExtensionsProjectSettings settings, ARCoreExtensionsConfig sessionConfig, UnityEditor.BuildTarget buildTarget) { string optionFeaturesSettings = "Edit > Project Settings > XR > ARCore Extensions > Optional Features"; if (sessionConfig.CloudAnchorMode != CloudAnchorMode.Disabled && !settings.CloudAnchorEnabled) { Debug.LogErrorFormat( "Cloud Anchors feature is required by CloudAnchorMode {0}. " + "It must be set in {1} > Cloud Anchors.", sessionConfig.CloudAnchorMode, optionFeaturesSettings); return(false); } else if (sessionConfig.GeospatialMode != GeospatialMode.Disabled && !settings.GeospatialEnabled) { Debug.LogErrorFormat( "Geospatial feature is required by GeospatialMode {0}. " + "It must be set in {1} > Geospatial.", sessionConfig.GeospatialMode, optionFeaturesSettings); return(false); } if (buildTarget == UnityEditor.BuildTarget.iOS) { string requirement = string.Empty; string iosAuthSettings = "Edit > Project Settings > XR > ARCore Extensions > " + "iOS Authentication Strategy"; if (sessionConfig.CloudAnchorMode == CloudAnchorMode.Enabled && settings.IOSAuthenticationStrategySetting == IOSAuthenticationStrategy.DoNotUse) { requirement = string.Format( "A valid authentication strategy is required by CloudAnchorMode {0}.", sessionConfig.CloudAnchorMode); } else if ( sessionConfig.GeospatialMode == GeospatialMode.Enabled && settings.IOSAuthenticationStrategySetting == IOSAuthenticationStrategy.DoNotUse) { requirement = string.Format( "A valid authentication strategy is required by GeospatialMode {0}.", sessionConfig.GeospatialMode); } if (string.IsNullOrEmpty(requirement)) { return(true); } else { Debug.LogErrorFormat("{0} It must be set in {1}.", requirement, iosAuthSettings); return(false); } } else { string requirement = string.Empty; string androidAuthSettings = "Edit > Project Settings > XR > ARCore Extensions > " + "Android Authentication Strategy"; if (sessionConfig.CloudAnchorMode == CloudAnchorMode.Enabled && settings.AndroidAuthenticationStrategySetting == AndroidAuthenticationStrategy.DoNotUse) { requirement = string.Format( "A valid authentication strategy is required by CloudAnchorMode {0}.", sessionConfig.CloudAnchorMode); } else if ( sessionConfig.GeospatialMode == GeospatialMode.Enabled && settings.AndroidAuthenticationStrategySetting == AndroidAuthenticationStrategy.DoNotUse) { requirement = string.Format( "A valid authentication strategy is required by GeospatialMode {0}.", sessionConfig.GeospatialMode); } if (string.IsNullOrEmpty(requirement)) { return(true); } else { Debug.LogErrorFormat("{0} It must be set in {1}.", requirement, androidAuthSettings); return(false); } } }