Search code examples
javakotlinaugmented-realityarcoresceneform

How to create Animation (changing Scaling, Rotation or Position) for a Node in ARCore Sceneform?


I'm using ARCore Sceneform libraries in Android Studio. I'm having trouble to find a method to perform a scaling animation to a node when it is set to enable (like the Quaternion used to rotate a node in Solar System by Google).

//On Tap Listener
scannerVisual.setOnTapListener(((hitTestResult, motionEvent) -> {

        // NodeAnimator arrow = new NodeAnimator(true);
        //arrow.setParent(scanner);

        Node arrowVisual = new Node();

        //StackOverflow Solution
        arrowVisual.setLocalPosition(new Vector3(0.5f, 0.0f, 0.0f));
        arrowVisual.setLocalScale(new Vector3(0.03f, 0.03f, 0.06f));
        arrowVisual.setRenderable(arrowRenderable);
        arrowVisual.setParent(scanner);

        // arrowVisual.setLocalRotation(Quaternion.axisAngle(new Vector3(0.0f, 1.0f, 0.0f), 90));
    })
);

I have something like this.


Solution

  • You need to set a local scale of the node before setting its parent. The code should look like this:

    Anchor anchor = hitResult.createAnchor();
    AnchorNode anchorNode = new AnchorNode(anchor);
    
    node.getScaleController().setMinScale(0.5f);
    node.getScaleController().setMaxScale(3.0f);
    
    node.setLocalScale(new Vector3(2.25f, 2.25f, 2.25f));
    node.setParent(anchorNode);
    

    Hope this helps.