Android AR sceneform vertical rotation

328 Views Asked by At

Trying to rotate sceneform 3d model to focus on camera and vertical rotation, it should not change angle based on camera angle, using TransformableNode for rotation with Quaternion

node.localRotation = Quaternion.axisAngle(Vector3(0f,0f,1f), 90f)

Its always rotating no matter what x,y,z value combination I give to try on Vector3, what I expected is like this always in all direction of camera Expected

But its rotating in a direction of camera and getting like this diff angle diff angle2

How do I always stick to vertical plane and not change the angle? Helps appreciated!. Thanks

1

There are 1 best solutions below

0
On

The orientation of anchors by default are points towards the camera. This results in models to be "looking at" the user. However, models on the wall/vertical plane end up rotating arbitrarily. This can be fixed by setting the look direction of the node.

you can introduce an intermediate node that fixes the orientation relative to the anchor node. Children of the intermediate node will then be oriented correctly.

Anchor anchor = hitResult.createAnchor();
anchorNode = new AnchorNode(anchor);
anchorNode.setParent(arFragment.getArSceneView().getScene());

// Create an intermediate node and orient it to be level by fixing look 
direction.
// This is needed specifically for nodes on walls.
Node intermediateNode = new Node();
intermediateNode.setParent(anchorNode);
Vector3 anchorUp = anchorNode.getUp();
intermediateNode.setLookDirection(Vector3.up(), anchorUp);