有什么方法可以在初始化 ArCore 时保留手部动作动画,但同时删除显示在手部动作动画后面的相机图片。
我正在使用
<fragment
android:id="@+id/Ar"
android:name="com.google.ar.sceneform.ux.ArFragment"
目前我正在隐藏整个片段:
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();
如有任何帮助,我们将不胜感激。
在运行带有
Hand Motion Animation
的“临时”视图时,在 ARCore/Sceneform 应用程序中隐藏 ArCamera feed 的最简单方法是使用 EXPOSE_HARDWARE_BUFFER
枚举的 case。要返回相机反馈,请点击屏幕以激活 BIND_TO_TEXTURE_EXTERNAL_OES
枚举案例。 这是代码:
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)
}
}
}
}