Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Mobile_AR_with_ARCore.pdf

Erik Hellman
November 19, 2018
64

 Mobile_AR_with_ARCore.pdf

Erik Hellman

November 19, 2018
Tweet

More Decks by Erik Hellman

Transcript

  1. User interaction Oriented Points Anchors and Trackables Augmented Images Cloud

    Anchors Moble AR with ARCore - @ErikHellman, Øredev 2018
  2. override fun onResume() { super.onResume() val arCoreApk = ArCoreApk.getInstance() if

    (!arCoreApk.checkAvailability(this).isSupported()) { // Not supported - notify user! return } if (arCoreApk.requestInstall(this, true) == ArCoreApk.InstallStatus.INSTALL_REQUESTED)) { // Installation needed - activity will pause return } // Everything is ok to go! } Moble AR with ARCore - @ErikHellman, Øredev 2018
  3. Sceneform → High-level scenegraph API → Realistic Physical Based Rendering

    using Filament → Android Studio plugin Moble AR with ARCore - @ErikHellman, Øredev 2018
  4. Sceneform dependencies { // Provides ARCore Session and related resources.

    implementation 'com.google.ar:core:1.5.0' // Provides ArFragment, and other UX resources. implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.5.1' // Alternatively, use ArSceneView without the UX dependency. implementation 'com.google.ar.sceneform:core:1.5.1' } Moble AR with ARCore - @ErikHellman, Øredev 2018
  5. Sceneform val arFragment = fragmentManager .findFragmentById(R.id.ux_fragment) as ArFragment? arFragment?.setOnTapArPlaneListener {

    hitResult, plane, motionEvent -> // Create new anchor and node val anchor = hitResult.createAnchor() val anchorNode = AnchorNode(anchor) // Add to the scene anchorNode.setParent(arFragment.arSceneView.scene) // TODO Add content to the new anchor... } Moble AR with ARCore - @ErikHellman, Øredev 2018
  6. Scneeform - Display models arFragment?.setOnTapArPlaneListener { hitResult, plane, motionEvent ->

    ModelRenderable.builder() .setSource(this, Uri.parse("earth.sfb")) .build() .thenAccept { val anchor = hitResult.createAnchor() val anchorNode = AnchorNode(anchor) val transformableNode = TransformableNode(arFragment.transformationSystem) .apply { setParent(anchorNode) renderable = it } anchorNode.addChild(transformableNode) anchorNode.setParent(arFragment.arSceneView.scene) } } Moble AR with ARCore - @ErikHellman, Øredev 2018
  7. Sceneform - Display Android views arFragment?.setOnTapArPlaneListener { hitResult, plane, motionEvent

    -> ViewRenderable.builder() .setView(this, R.layout.simple_form) .build() .thenAccept { card -> val anchor = hitResult.createAnchor() val anchorNode = AnchorNode(anchor) TransformableNode(arFragment.transformationSystem).apply { setParent(anchorNode) renderable = card select() } anchorNode.setParent(arFragment.arSceneView.scene) card.view.findViewById<Button>(R.id.okBtn).setOnClickListener { arFragment.arSceneView.scene.removeChild(anchorNode) anchor.detach() } } Moble AR with ARCore - @ErikHellman, Øredev 2018
  8. Configure Augmented Images // ARCore session sestup val session =

    Session(this) val config = Config(session) // Open image database val inputStream = context.assets.open("my_images_db.imgdb") val imageDatabase = AugmentedImageDatabase.deserialize(inputStream); // Enable image tracking config.setAugmentedImageDatabase(imageDatabase); session.configure(config); Moble AR with ARCore - @ErikHellman, Øredev 2018
  9. Track images // in onDrawFrame() val frame = session.update() val

    updatedAugmentedImages = frame.getUpdatedTrackables(AugmentedImage::class.java) updatedAugmentedImages.forEach { when (it.trackingState) { TrackingState.PAUSE -> // Detected, but not yet tracked TrackingState.TRACKING -> // Tracking! Create an anchor TrackingState.STOPPED -> // Remove anchor } } Moble AR with ARCore - @ErikHellman, Øredev 2018