Reputation: 31
Is there any way to preserve the hand motion animation when initializing ArCore but simultaneously getting rid of the camera picture - which is displayed behind the hand motion animation.
I am using
<fragment
android:id="@+id/Ar"
android:name="com.google.ar.sceneform.ux.ArFragment"
and currently I am hiding the whole Fragment with:
fragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.Ar);
fm = getSupportFragmentManager();
fm.beginTransaction()
.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
.hide(fragment)
.commit();
Any help is appreciated.
Upvotes: 3
Views: 212
Reputation: 58113
The easiest way to hide the ArCamera feed in ARCore/Sceneform app, while a "temporary" view with Hand Motion Animation
is running, is to use EXPOSE_HARDWARE_BUFFER
enum's case. In order to return the camera feed back, tap on the screen to activate BIND_TO_TEXTURE_EXTERNAL_OES
enum case. Here's the code:
class MainActivity : AppCompatActivity() {
private lateinit var arFragment: ArFragment
private lateinit var session: Session
private lateinit var texture: Texture
private fun configure(session: Session, withFrag: ArFragment) {
val config = Config(session)
config.updateMode = Config.UpdateMode.LATEST_CAMERA_IMAGE
config.textureUpdateMode = Config.TextureUpdateMode.EXPOSE_HARDWARE_BUFFER
session.configure(config)
withFrag.arSceneView.setupSession(session)
withFrag.arSceneView.scene.setOnTouchListener { _, _ ->
config.textureUpdateMode = Config.TextureUpdateMode.BIND_TO_TEXTURE_EXTERNAL_OES
session.configure(config)
return@setOnTouchListener true
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
arFragment = supportFragmentManager.findFragmentByTag("frag") as ArFragment
this.session = Session(this)
configure(session, arFragment)
addCelestialBodyToSceneIn(arFragment)
}
private fun addCelestialBodyToSceneIn(frag: ArFragment) {
Texture
.builder()
.setSource(this, R.drawable.mars)
.build()
.thenAccept {
this.texture = it
MaterialFactory.makeOpaqueWithTexture(this, texture)
.thenAccept { shader ->
val sphere = ShapeFactory.makeSphere(0.3f, Vector3(), shader)
val node = Node()
node.renderable = sphere
node.worldPosition = Vector3(0f, 0f,-2f)
frag.arSceneView.scene.addChild(node)
}
}
}
}
Upvotes: 0