在没有ArCore的情况下与SceneView内部的3D模型进行交互

时间:2019-07-05 08:50:45

标签: android 3d arcore

我想在没有Camera和ArCore的Sceneview上加载3D对象。所以我创建了一个简单的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

现在的问题是如何与3D对象交互,旋转,缩放和拾取元素?我看到使用ArCore有TransformableNodes,但是如果没有ArCore怎么使用呢?

0 个答案:

没有答案