Search code examples
javaandroidarcoresceneform

ARCore – Disable a movement of ModelRenderable


Here is the piece of code using which I am able to place the model.

private void addNodeToScene(ArFragment fragment, Anchor createAnchor, ModelRenderable renderable) {

    AnchorNode anchorNode = new AnchorNode(createAnchor);
    TransformableNode transformableNode = new TransformableNode(fragment.getTransformationSystem());
    transformableNode.setName("box");
    transformableNode.setRenderable(renderable);
    transformableNode.setParent(anchorNode);
    fragment.getArSceneView().getScene().addChild(anchorNode);

    transformableNode.setOnTapListener((hitTestResult, motionEvent) -> {
        if(callback != null) {
            callback.onGiftClick(hitTestResult.getNode());
        }
    });
    transformableNode.select();
}

But once the model is placed, I can move the model around.

Is there any way I can disable the user from moving the model around once it has been placed?


Solution

  • replace your TransformableNode with a Node.

    TransformableNode transformableNode = new TransformableNode(fragment.getTransformationSystem());
    

    becomes

    Node myNode = new Node();
    

    you won't be able to move it then anymore

    Some things work differently with Nodes as opposed to TransformableNodes -> The constructor being empty.