如何删除放置在 AR 屏幕上的 3D 对象

Vam*_*hna 1 android android-sdk-manager arcore

我有一个 AR 屏幕,我在其中放置了一些 3D 对象。我正在使用 google AR Core 和 android SDK。

我需要通过单击清除按钮从场景中删除这些对象。

我能够删除最后放置的物体。但其他物体并没有被移除。

这是我正在使用的代码。

if (newAnchor != null) {
            arFragment.getArSceneView().getScene().removeChild(newAnchor);
            newAnchor.getAnchor().detach();
Run Code Online (Sandbox Code Playgroud)

Bil*_*ilz 5

您可以使用下面的代码将 Android 模型从场景表单中分离出来

 List<Node> children = new ArrayList<>(arFragment.getArSceneView().getScene().getChildren());
        for (Node node : children) {
            if (node instanceof AnchorNode) {
                if (((AnchorNode) node).getAnchor() != null) {
                    ((AnchorNode) node).getAnchor().detach();
                }
            }
            if (!(node instanceof Camera) && !(node instanceof Sun)) {
                node.setParent(null);
            }
        }
Run Code Online (Sandbox Code Playgroud)