Sceneform-android-sdk: How can i remove displaying of a model once it is rendered on the screen with anchornode as its parent?

Created on 29 Jan 2019  路  12Comments  路  Source: google-ar/sceneform-android-sdk

This is what i am doing..
Now i added a button so how can i stop rendering the model by clicking the button?

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

TransformableNode model = new TransformableNode(arFragment.getTransformationSystem());
model.setParent(anchorNode);
model.setRenderable(sauce);
model.select();

Most helpful comment

Sorry if my explanation wasn't clear! Taking a step back, it looks like you are actually trying to remove an object you previously placed, not toggle an existing object on and off?

To do this, you'll need to store the AnchorNode you create in a class-level member variable, so that you can remove if from the scene when the next one is placed.

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

TransformableNode model = new TransformableNode(arFragment.getTransformationSystem());
model.setParent(anchorNode);
model.select();

if(point==0) {
    model.setRenderable(sauce);
} else if(point ==1) {
    model.setRenderable(chickenren);
}

if (previousAnchorNode != null) {
    previousAnchorNode.setParent(null);
}

previousAnchorNode = anchorNode;

All 12 comments

Try doing model.setEnabled(false)

Nope it didnt remove the obj . its still there

This is basically what im doing.. i added a button which toggles point value to 0 or 1..
according to point value it decides which model to add on tap.

So what i want to do that after i toggle my old object should be gone from the screen for a new one to appear.
arFragment.setOnTapArPlaneListener(
(HitResult hitResult, Plane plane, MotionEvent motionEvent)->{

                if(plane.getType() != Plane.Type.HORIZONTAL_UPWARD_FACING)
                    return;

                Anchor anchor = hitResult.createAnchor();
                AnchorNode anchorNode = new AnchorNode(anchor);
                anchorNode.setParent(arFragment.getArSceneView().getScene());
                TransformableNode chicken = new TransformableNode(arFragment.getTransformationSystem());
                TransformableNode model = new TransformableNode(arFragment.getTransformationSystem());
                if(point==0) {

                    model.setParent(anchorNode);
                    model.setRenderable(sauce);
                    model.select();


                }
                else if(point ==1) {
                    chicken.setParent(anchorNode);
                    chicken.setRenderable(chickenren);
                    chicken.select();


                }


            });

Ah, it's because the AnchorNode controls the enabled state of it's children. I suggest trying to create an intermediary node between the AnchorNode and the model. Then, the AnchorNode will control if the intermediary node is enabled, and you can directly control if the model node is enabled.

can you show me that in the code? what should i add
?

Actually, my suggestion likely won't work because the TransformableNode expects to be a direct child of an AnchorNode.

Though I may have been over complicating this, I think you should just be able to set the enabled state of the AnchorNode itself.

huh??!!

Sorry if my explanation wasn't clear! Taking a step back, it looks like you are actually trying to remove an object you previously placed, not toggle an existing object on and off?

To do this, you'll need to store the AnchorNode you create in a class-level member variable, so that you can remove if from the scene when the next one is placed.

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

TransformableNode model = new TransformableNode(arFragment.getTransformationSystem());
model.setParent(anchorNode);
model.select();

if(point==0) {
    model.setRenderable(sauce);
} else if(point ==1) {
    model.setRenderable(chickenren);
}

if (previousAnchorNode != null) {
    previousAnchorNode.setParent(null);
}

previousAnchorNode = anchorNode;

you are awesome... <3
thanks very much sir

just for my information .. can you tell me that whats the initial parent for the anchornode?? isnt it the root node?

When any Node is first instantiated it's parent is null. The node must then be added to the scene, which I see you are already doing in your code.

ooooooh ok i see. thanks a ton

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yashvv picture yashvv  路  3Comments

michaelvogt picture michaelvogt  路  4Comments

arilotter picture arilotter  路  3Comments

JessHolle picture JessHolle  路  3Comments

peronecode picture peronecode  路  3Comments