This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//add ar core | |
implementation 'com.google.ar:core:1.3.0' | |
implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.3.0' | |
implementation 'com.google.ar.sceneform:core:1.3.0' | |
//in top of file | |
apply plugin: 'com.google.ar.sceneform.plugin' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-feature android:name="android.hardware.camera.ar" android:required="true" /> | |
<uses-permission android:name="android.permission.CAMERA" /> | |
//and in <application> section: | |
<meta-data android:name="com.google.ar.core" android:value="required" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in onResume: | |
try { | |
if (mSession == null) { | |
switch (ArCoreApk.getInstance().requestInstall(this, mUserRequestedInstall)) { | |
case INSTALLED: | |
mSession = new Session(this); | |
// Success. | |
break; | |
case INSTALL_REQUESTED: | |
// Ensures next invocation of requestInstall() will either return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun loadAugmentedEarthImage(): Bitmap? { | |
try { | |
assets.open("earth.jpg").use { `is` -> return BitmapFactory.decodeStream(`is`) } | |
} catch (e: IOException) { | |
Log.e(TAG, "IO exception loading augmented image bitmap.", e) | |
} | |
return null | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun setupAugmentedImageDb(config: Config): Boolean { | |
val augmentedImageDatabase = AugmentedImageDatabase(session) | |
val augmentedEarthImageBitmap = loadAugmentedEarthImage() ?: return false | |
augmentedImageDatabase.addImage("earth", augmentedEarthImageBitmap) | |
config.augmentedImageDatabase = augmentedImageDatabase | |
return true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun configureSession() { | |
val config = Config(session) | |
if (setupAugmentedImageDb(config).not()) { | |
messageSnackbarHelper.showError(this, "Could not setup augmented image database") | |
} | |
config.updateMode = Config.UpdateMode.LATEST_CAMERA_IMAGE | |
session.configure(config) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun onUpdateFrame() { | |
frame = surfaceview.arFrame | |
camera = frame.camera | |
val updatedAugmentedImages = frame.getUpdatedTrackables(AugmentedImage::class.java) | |
camera.getProjectionMatrix(projmtx, 0, 0.1f, 100.0f) | |
camera.getViewMatrix(viewmtx, 0) | |
for (augmentedImage in updatedAugmentedImages) { | |
if (augmentedImage.trackingState == TrackingState.TRACKING) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
surfaceview.scene.setOnUpdateListener { this.onUpdateFrame() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<android.opengl.GLSurfaceView | |
android:id="@+id/surfaceviewGl" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_gravity="center" | |
android:visibility="invisible"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
surfaceviewGl.setZOrderOnTop(true) | |
surfaceviewGl.preserveEGLContextOnPause = true | |
surfaceviewGl.setEGLContextClientVersion(2) | |
surfaceviewGl.holder.setFormat(PixelFormat.RGBA_8888); | |
surfaceviewGl.setEGLConfigChooser(8, 8, 8, 8, 16, 0) | |
surfaceviewGl.setRenderer(this) |