protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Main); mSurfaceView = FindViewById <GLSurfaceView>(Resource.Id.surfaceview); mDisplayRotationHelper = new DisplayRotationHelper(this); Java.Lang.Exception exception = null; string message = null; try { mSession = new Session(/*context=*/ this); } catch (UnavailableArcoreNotInstalledException e) { message = "Please install ARCore"; exception = e; } catch (UnavailableApkTooOldException e) { message = "Please update ARCore"; exception = e; } catch (UnavailableSdkTooOldException e) { message = "Please update this app"; exception = e; } catch (Java.Lang.Exception e) { exception = e; message = "This device does not support AR"; } if (message != null) { Toast.MakeText(this, message, ToastLength.Long).Show(); return; } // Create default config, check is supported, create session from that config. var config = new Google.AR.Core.Config(mSession); if (!mSession.IsSupported(config)) { Toast.MakeText(this, "This device does not support AR", ToastLength.Long).Show(); Finish(); return; } mGestureDetector = new Android.Views.GestureDetector(this, new SimpleTapGestureDetector { SingleTapUpHandler = (MotionEvent arg) => { onSingleTap(arg); return(true); }, DownHandler = (MotionEvent arg) => true }); mSurfaceView.SetOnTouchListener(this); // Set up renderer. mSurfaceView.PreserveEGLContextOnPause = true; mSurfaceView.SetEGLContextClientVersion(2); mSurfaceView.SetEGLConfigChooser(8, 8, 8, 8, 16, 0); // Alpha used for plane blending. mSurfaceView.SetRenderer(this); mSurfaceView.RenderMode = Rendermode.Continuously; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Main); mSurfaceView = FindViewById <GLSurfaceView>(Resource.Id.surfaceview); mSession = new Session(/*context=*/ this); // Create default config, check is supported, create session from that config. mDefaultConfig = Google.AR.Core.Config.CreateDefaultConfig(); if (!mSession.IsSupported(mDefaultConfig)) { Toast.MakeText(this, "This device does not support AR", ToastLength.Long).Show(); Finish(); return; } mGestureDetector = new Android.Views.GestureDetector(this, new SimpleTapGestureDetector { SingleTapUpHandler = (MotionEvent arg) => { onSingleTap(arg); return(true); }, DownHandler = (MotionEvent arg) => true }); mSurfaceView.SetOnTouchListener(this); // Set up renderer. mSurfaceView.PreserveEGLContextOnPause = true; mSurfaceView.SetEGLContextClientVersion(2); mSurfaceView.SetEGLConfigChooser(8, 8, 8, 8, 16, 0); // Alpha used for plane blending. mSurfaceView.SetRenderer(this); mSurfaceView.RenderMode = Rendermode.Continuously; }
private void SetupSessionForSceneView(Context context, ArSceneView sceneView) { try { Session session = new Session(context); Config config = new Config(session); config.SetUpdateMode(Config.UpdateMode.LatestCameraImage); session.Configure(config); sceneView.SetupSession(session); } catch (Exception ex) { Android.Util.Log.Error("ASADemo: ", ex.ToString()); } }
/// <summary> /// Creates the AR Renderer /// </summary> public BaseArRenderer(Context context, GLSurfaceView surfaceView) { this.context = context; this.surfaceView = surfaceView; this.session = new Session(this.context); this.displayRotationHelper = new DisplayRotationHelper(this.context); config = new Google.AR.Core.Config(this.session); if (!session.IsSupported(config)) { return; } this.surfaceView.PreserveEGLContextOnPause = true; this.surfaceView.SetEGLContextClientVersion(2); this.surfaceView.SetEGLConfigChooser(8, 8, 8, 8, 16, 0); }
/// <inheritdoc /> public override void Dispose() { this.cameraTexture = null; if (this.backgroundCameraMesh != null) { WaveServices.GraphicsDevice.DestroyIndexBuffer(this.backgroundCameraMesh.IndexBuffer); WaveServices.GraphicsDevice.DestroyVertexBuffer(this.backgroundCameraMesh.VertexBuffer); this.backgroundCameraMesh = null; } this.currentFrame?.Dispose(); this.currentFrame = null; this.arCoreSession?.Dispose(); this.arCoreSession = null; this.arConfiguration?.Dispose(); this.arConfiguration = null; this.platform.OnDisplayOrientationChanged -= this.Platform_OnDisplayOrientationChanged; this.platform.OnScreenSizeChanged -= this.Platform_OnScreenSizeChanged; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Main); mSurfaceView = FindViewById <GLSurfaceView>(Resource.Id.surfaceview); mDisplayRotationHelper = new DisplayRotationHelper(this); Java.Lang.Exception exception = null; string message = null; try { mSession = new Session(/*context=*/ this); } catch (UnavailableArcoreNotInstalledException e) { message = "Please install ARCore"; exception = e; } catch (UnavailableApkTooOldException e) { message = "Please update ARCore"; exception = e; } catch (UnavailableSdkTooOldException e) { message = "Please update this app"; exception = e; } catch (Java.Lang.Exception e) { exception = e; message = "This device does not support AR"; } if (message != null) { Toast.MakeText(this, message, ToastLength.Long).Show(); return; } // Create default config, check is supported, create session from that config. var config = new Google.AR.Core.Config(mSession); if (!mSession.IsSupported(config)) { Toast.MakeText(this, "This device does not support AR", ToastLength.Long).Show(); Finish(); return; } AugmentedImageDatabase imageDatabase = new AugmentedImageDatabase(mSession); Bitmap bitmap = null; try { var inputStream = Assets.Open("qrcode.png"); bitmap = BitmapFactory.DecodeStream(inputStream); } catch (IOException e) { Log.Error(TAG, "I/O exception loading augmented image bitmap.", e); } index = imageDatabase.AddImage("interstellar", bitmap, 0.01f); config.AugmentedImageDatabase = imageDatabase; mSession.Configure(config); mGestureDetector = new GestureDetector(this, new TapGestureDetector { SingleTapUpHandler = (MotionEvent arg) => { OnSingleTap(arg); return(true); }, DownHandler = (MotionEvent arg) => true }); mSurfaceView.SetOnTouchListener(this); // Set up renderer. mSurfaceView.PreserveEGLContextOnPause = true; mSurfaceView.SetEGLContextClientVersion(2); mSurfaceView.SetEGLConfigChooser(8, 8, 8, 8, 16, 0); // Alpha used for plane blending. mSurfaceView.SetRenderer(this); mSurfaceView.RenderMode = Rendermode.Continuously; }
protected override void OnElementChanged(ElementChangedEventArgs <ARView> e) { base.OnElementChanged(e); if (e.OldElement != null || Element == null) { return; } try { mSurfaceView = new GLSurfaceView(_context); mDisplayRotationHelper = new DisplayRotationHelper(_context); Java.Lang.Exception exception = null; string message = null; try { mSession = new Session(_context); } //catch (UnavailableArcoreNotInstalledException ex) //{ // message = "Please install ARCore"; // exception = ex; //} //catch (UnavailableApkTooOldException ex) //{ // message = "Please update ARCore"; // exception = ex; //} //catch (UnavailableSdkTooOldException ex) //{ // message = "Please update this app"; // exception = ex; //} catch (Java.Lang.Exception ex) { exception = ex; message = "This device does not support AR"; } if (message != null) { Toast.MakeText(_context, message, ToastLength.Long).Show(); return; } var config = new Google.AR.Core.Config(mSession); if (!mSession.IsSupported(config)) { Toast.MakeText(_context, "This device does not support AR", ToastLength.Long).Show(); return; } mGestureDetector = new Android.Views.GestureDetector(_context, new SimpleTapGestureDetector { SingleTapUpHandler = (MotionEvent arg) => { onSingleTap(arg); return(true); }, DownHandler = (MotionEvent arg) => true }); mSurfaceView.SetOnTouchListener(this); mSurfaceView.PreserveEGLContextOnPause = true; mSurfaceView.SetEGLContextClientVersion(2); mSurfaceView.SetEGLConfigChooser(8, 8, 8, 8, 16, 0); // Alpha used for plane blending. mSurfaceView.SetRenderer(this); mSurfaceView.RenderMode = Rendermode.Continuously; SetNativeControl(mSurfaceView); mSession.Resume(); mSurfaceView.OnResume(); mDisplayRotationHelper.OnResume(); showLoadingMessage(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(@" ERROR: ", ex.Message); } }
protected override void OnElementChanged(ElementChangedEventArgs <Page> e) { base.OnElementChanged(e); if (e.OldElement != null || Element == null) { return; } try { //need to add this on main layout //mSurfaceView = FindViewById<GLSurfaceView>(Resource.Id.surfaceview); Java.Lang.Exception exception = null; string message = null; try { //Create session //mSession = new Session(_context); } //catch (UnavailableArcoreNotInstalledException ex) //{ // message = "Please install ARCore"; // exception = ex; //} //catch (UnavailableApkTooOldException ex) //{ // message = "Please update ARCore"; // exception = ex; //} //catch (UnavailableSdkTooOldException ex) //{ // message = "Please update this app"; // exception = ex; //} catch (Java.Lang.Exception ex) { exception = ex; message = "This device does not support AR"; } if (message != null) { Toast.MakeText(_context, message, ToastLength.Long).Show(); return; } // Create default config, check is supported, create session from that config. var config = new Google.AR.Core.Config(mSession); if (!mSession.IsSupported(config)) { Toast.MakeText(_context, "This device does not support AR", ToastLength.Long).Show(); return; } mGestureDetector = new Android.Views.GestureDetector(_context, new SimpleTapGestureDetector { SingleTapUpHandler = (MotionEvent arg) => { onSingleTap(arg); return(true); }, DownHandler = (MotionEvent arg) => true }); mSurfaceView.SetOnTouchListener(this); // Set up renderer. mSurfaceView.PreserveEGLContextOnPause = true; mSurfaceView.SetEGLContextClientVersion(2); mSurfaceView.SetEGLConfigChooser(8, 8, 8, 8, 16, 0); // Alpha used for plane blending. mSurfaceView.SetRenderer(this); mSurfaceView.RenderMode = Rendermode.Continuously; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(@" ERROR: ", ex.Message); } }
/// <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); }
private void StartArSession() { displayRotationHelper = new DisplayRotationHelper(this); string message = null; Java.Lang.Exception exception = null; arSession = null; try { arSession = new Session(/*context=*/ this); } catch (UnavailableArcoreNotInstalledException e) { message = "Please install ARCore"; exception = e; } catch (UnavailableApkTooOldException e) { message = "Please update ARCore"; exception = e; } catch (UnavailableSdkTooOldException e) { message = "Please update this app"; exception = e; } catch (CameraAccessException e) { message = "CameraAccessException"; exception = e; } catch (Java.Lang.Exception e) { exception = e; message = "This device does not support AR"; } if (message != null) { Toast.MakeText(this, message, ToastLength.Long).Show(); return; } var config = new Google.AR.Core.Config(arSession); //var cameraConfigs = arSession.GetSupportedCameraConfigs(new CameraConfigFilter(arSession)); //arSession.CameraConfig = cameraConfigs.First(c => c.ImageSize.Height == 1080); if (!arSession.IsSupported(config)) { Toast.MakeText(this, "This device does not support AR", ToastLength.Long).Show(); Finish(); return; } arSession.Configure(config); gestureDetector = new GestureDetector(this, new SimpleTapGestureDetector { SingleTapUpHandler = (args) => { OnSingleTap(args); return(true); }, DownHandler = _ => true }); }