我想在Sceneview上加载一个3D对象,不需要相机和ArCore。因此,我创建了一个简单的xml布局如下:
<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">
<com.google.ar.sceneform.SceneView
android:id="@+id/scene"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
然后像这样加载3D对象:
private fun renderObject() {
ModelRenderable.builder()
.setSource(this, R.raw.andy)
.build()
.thenAccept {
it?.let {
node = Node().apply {
setParent(scene)
localPosition = Vector3(0f, 0f, -1f)
localScale = Vector3(3f, 3f, 3f)
name = "Andy"
renderable = it
}
scene.addChild(node)
}
}
.exceptionally {
val builder = AlertDialog.Builder(this)
builder.setMessage(it.message)
.setTitle("error!")
val dialog = builder.create()
dialog.show()
return@exceptionally null
}
}
我得到了我期望的3D对象:
![enter image description here](https://istack.dev59.com/sB3D6.webp)
现在的问题是如何与这个3D对象进行交互,旋转、缩放和选择元素?我看到使用ArCore有TransformableNodes,但如何在没有ArCore的情况下使用它呢?