Skip to content

Instantly share code, notes, and snippets.

View Ayusch's full-sized avatar

Ayusch Jain Ayusch

View GitHub Profile
private fun cloudAnchor(newAnchor: Anchor?) {
cloudAnchor?.detach()
cloudAnchor = newAnchor
appAnchorState = AppAnchorState.NONE
snackbarHelper.hide(this)
}
arFragment.setOnTapArPlaneListener { hitResult, plane, _ ->
if (plane.type != Plane.Type.HORIZONTAL_UPWARD_FACING || appAnchorState != AppAnchorState.NONE) {
return@setOnTapArPlaneListener
}
val anchor = arFragment.arSceneView.session?.hostCloudAnchor(hitResult.createAnchor())
placeObject(arFragment, cloudAnchor!!, Uri.parse("model.sfb"))
}
private fun cloudAnchor(newAnchor: Anchor?) {
cloudAnchor?.detach()
cloudAnchor = newAnchor
appAnchorState = AppAnchorState.NONE
snackbarHelper.hide(this)
}
private fun placeObject(fragment: ArFragment, anchor: Anchor, model: Uri) {
ModelRenderable.Builder()
.setSource(fragment.context, model)
.build()
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment
android:id="@+id/ar_fragment"
class CloudAnchorFragment : ArFragment() {
override fun getSessionConfiguration(session: Session?): Config {
planeDiscoveryController.setInstructionView(null)
val config: Config = super.getSessionConfiguration(session)
config.cloudAnchorMode = Config.CloudAnchorMode.ENABLED
return config
}
}
implementation 'com.google.ar:core:1.10.0'
implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.10.0'
implementation 'com.google.android.material:material:1.0.0'
<meta-data
android:name="com.google.ar.core"
android:value="required"/>
<meta-data
android:name="com.google.android.ar.API_KEY"
android:value="YOUR API KEY"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-feature android:name="android.hardware.camera.ar" android:required="true"/>
private fun processFaceResult(faces: MutableList<FirebaseVisionFace>) {
faces.forEach {
val bounds = it.boundingBox
val rectOverLay = RectOverlay(graphic_overlay, bounds)
graphic_overlay.add(rectOverLay)
}
alertDialog.dismiss()
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity">
<Button android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"