/// <inheritdoc />
        public override Task <bool> StartTracking(ARMobileStartOptions startOptions)
        {
            if (!UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                throw new NotSupportedException("ARKit requires iOS11 or higher");
            }

            if (this.arkitSession == null)
            {
                this.arkitSession          = new ARSession();
                this.arkitSession.Delegate = new ARKitSessionDelegate(this);
            }
            else if ((startOptions & ARMobileStartOptions.ResetTracking) != 0 ||
                     (startOptions & ARMobileStartOptions.RemoveExistingAnchors) != 0)
            {
                this.ClearAllAnchors();
            }

            this.arkitSession.Run(this.aRConfiguration, startOptions.ToARKit());

            return(Task.FromResult(true));
        }
 /// <summary>
 /// Starts the tracking process
 /// </summary>
 /// <param name="startOptions">
 /// Options affecting how existing session state (if any) transitions to the new configuration.
 /// If the session is starting for the first time, this parameter has no effect.
 /// </param>
 /// <returns>
 ///   <c>true</c>, if tracking was started, <c>false</c> otherwise.
 /// </returns>
 public Task <bool> StartTracking(ARMobileStartOptions startOptions)
 {
     return(this.service?.StartTracking(startOptions));
 }
Esempio n. 3
0
 /// <summary>
 /// Converts an <see cref="ARMobileStartOptions"/> into a <see cref="ARSessionRunOptions"/>.
 /// </summary>
 /// <param name="startOptions">The start options value to be converted</param>
 /// <returns>Returns an <see cref="ARSessionRunOptions"/></returns>
 internal static ARSessionRunOptions ToARKit(this ARMobileStartOptions startOptions)
 {
     return((ARSessionRunOptions)startOptions);
 }
Esempio n. 4
0
        /// <inheritdoc />
        public override async Task <bool> StartTracking(ARMobileStartOptions startOptions)
        {
            bool result = false;

            if (this.arCoreSession != null)
            {
                var hasResetTracking = (startOptions & ARMobileStartOptions.ResetTracking) != 0;

                if (hasResetTracking ||
                    (startOptions & ARMobileStartOptions.RemoveExistingAnchors) != 0)
                {
                    this.ClearAllAnchors();
                }
                else if (!hasResetTracking)
                {
                    this.arCoreSession.Resume();
                    result = true;
                }
            }

            if (!result)
            {
                this.currentFrame?.Dispose();
                this.arCoreSession?.Dispose();
                this.arConfiguration?.Dispose();

                try
                {
                    var adapter = Game.Current.Application.Adapter as WaveEngine.Adapter.Adapter;

                    var isSupported = await this.initializationTCS.Task;
                    if (!isSupported)
                    {
                        throw new Exception("This device does not support AR");
                    }

                    if (ArCoreApk.Instance.RequestInstall(adapter.Activity, true) != ArCoreApk.InstallStatus.Installed)
                    {
                        throw new UnavailableArcoreNotInstalledException();
                    }

                    // ARCore requires camera permissions to operate. If we did not yet obtain runtime
                    // permission on Android M and above, now is a good time to ask the user for it.
                    if (ContextCompat.CheckSelfPermission(adapter.Activity, Android.Manifest.Permission.Camera) != Android.Content.PM.Permission.Granted)
                    {
                        ActivityCompat.RequestPermissions(adapter.Activity, new string[] { Android.Manifest.Permission.Camera }, 0);

                        throw new UnauthorizedAccessException("Camera permission is needed");
                    }

                    this.arCoreSession = new Session(adapter.Activity);

                    // Create default config, check is supported, create session from that config.
                    this.arConfiguration = new ARConfig(this.arCoreSession);
                    if (!this.arCoreSession.IsSupported(this.arConfiguration))
                    {
                        throw new Exception("This device does not support AR");
                    }

                    this.isSupported     = true;
                    this.viewportChanged = true;

                    if (this.cameraTexture != null)
                    {
                        this.arCoreSession.SetCameraTextureName((int)this.cameraTexture.TextureHandle);
                    }

                    this.RefreshConfiguration();
                    this.Reset();

                    result = true;
                }
                catch (UnavailableArcoreNotInstalledException)
                {
                    Log.WriteLine(LogPriority.Error, TAG, "Please install ARCore");
                }
                catch (UnavailableApkTooOldException)
                {
                    Log.WriteLine(LogPriority.Error, TAG, "Please update ARCore");
                }
                catch (UnavailableSdkTooOldException)
                {
                    Log.WriteLine(LogPriority.Error, TAG, "Please update this app");
                }
                catch (Java.Lang.Exception ex)
                {
                    Log.WriteLine(LogPriority.Error, TAG, $"This device does not support AR. Error details: {ex.ToString()}");
                }
                catch (Exception ex)
                {
                    Log.WriteLine(LogPriority.Error, TAG, $"{ex.Message}");
                }
            }

            return(result);
        }
Esempio n. 5
0
 /// <summary>
 /// Starts the tracking process
 /// </summary>
 /// <param name="startOptions">
 /// Options affecting how existing session state (if any) transitions to the new configuration.
 /// If the session is starting for the first time, this parameter has no effect.
 /// </param>
 /// <returns>
 ///   <c>true</c>, if tracking was started, <c>false</c> otherwise.
 /// </returns>
 public abstract Task <bool> StartTracking(ARMobileStartOptions startOptions);