'interact with 3D model inside SceneView without ArCore
I'd like to load a 3D object on a Sceneview without Camera and ArCore. So I created a simple xml layout like so:
<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:
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:
Now the problem is how to interact with this 3D object, rotate, zoom, and pick an element? I see that using ArCore there is TransformableNodes but how can I use it without ArCore?
Solution 1:[1]
There is a working example here in this repo: https://github.com/chnouman/SceneView
It uses a custom node
(DragTransformableNode
). The relevant snippet is in 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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | VIN |