[英]interact with 3D model inside SceneView without ArCore
I'd like to load a 3D object on a Sceneview without Camera and ArCore.我想在没有相机和 ArCore 的 Sceneview 上加载 3D object。 So I created a simple xml layout like so:
所以我创建了一个简单的 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>
and loaded 3D object like so:并像这样加载 3D object:
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
}
}
and I get my 3D object as expected:我按预期得到了 3D object:
Now the problem is how to interact with this 3D object, rotate, zoom, and pick an element?现在的问题是如何与这个 3D object 交互,旋转,缩放,拾取一个元素? I see that using ArCore there is TransformableNodes but how can I use it without ArCore?
我看到使用 ArCore 有TransformableNodes但没有 ArCore 我怎么能使用它呢?
There is a working example here in this repo: https://github.com/chnouman/SceneView此回购协议中有一个工作示例: https://github.com/chnouman/SceneView
It uses a custom node
( DragTransformableNode
).它使用自定义
node
( DragTransformableNode
)。 The relevant snippet is in SceneViewActivity.kt
.相关片段在
SceneViewActivity.kt
中。
private fun addNodeToScene(model: ModelRenderable) {
if (sceneView != null) {
val transformationSystem = makeTransformationSystem()
var dragTransformableNode = DragTransformableNode(1f, transformationSystem)
dragTransformableNode?.renderable = model
sceneView.getScene().addChild(dragTransformableNode)
dragTransformableNode?.select()
sceneView.getScene()
.addOnPeekTouchListener { hitTestResult: HitTestResult?, motionEvent: MotionEvent? ->
transformationSystem.onTouch(
hitTestResult,
motionEvent
)
}
}
}
I have forked this repo and am working on keyboard input support if anyone's interested in that.如果有人对此感兴趣,我已经分叉了这个 repo 并正在研究键盘输入支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.