Abdul Mateen
Abdul Mateen

Reputation: 1674

Can I rotate a 3D object in ARCore without using ARFragment?

I am working on a simple Android app using Sceneform in which I have to rotate a 3D object when a user taps on it. I know I can do it in ArFragment, but I don't want to use Augmented Reality for this purpose. I am simply using Sceneform as a 3D viewer and the only interaction user needs is to tap the display in order to rotate the model. Is it possible in ARCore without using its Augmented Reality shenanigans?

Upvotes: 1

Views: 1007

Answers (1)

stewe93
stewe93

Reputation: 103

Yes it is! You should use only the SceneView component in your layout instead of the <fragment... block and from this point, everything is the same as with ArFragment. About the rotation: You still can use the TransformableNode (https://developers.google.com/ar/reference/java/sceneform/reference/com/google/ar/sceneform/ux/TransformableNode) if you want, it's not tied to the ArFragment or you could implement a basic rotation on tap:

node.setOnTapListener { hitTestResult, motionEvent ->
   node.localRotation = Quaternion.multiply(node.localRotation, Quaternion(Vector3.up(), 180f))
}

This would rotate your node by 180 degree.

Upvotes: 3

Related Questions