如何在 flutter 中删除 AR 核心节点

How to remove a AR core node in flutter

我是flutter新手,尤其是arcore_flutter_plugin。我已完成初始化并显示 ArCoreNode,但我无法找到 remove/delete 这些已初始化节点的方法。 我如何初始化节点:

@override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text(entity),
        ),
        body: ArCoreView(
          onArCoreViewCreated: _onArCoreViewCreated,
          enableTapRecognizer: true,
        ),
      ),
    );
  }
void _onArCoreViewCreated(ArCoreController controller) {
    arCoreController = controller;
    _addEntityNode(arCoreController);
  }

void _addEntityNode(ArCoreController controller) {
    final entityNode = ArCoreReferenceNode(
        name: entity,
        objectUrl:
        "${objectKeys[entity.toLowerCase()]["3d_model_URI"]}",
        position: vector.Vector3(
          0, 0, -1
        ),
    );

    arCoreController.addArCoreNode(entityNode);
  }

目的是删除不在 context/are 未选择的节点。

您可以使用 removeNode 函数来完成此操作。它有一个参数,就是你要移除的节点名称。

所以在您的代码中这样做的方式是:

@override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text(entity),
        ),
        body: ArCoreView(
          onArCoreViewCreated: _onArCoreViewCreated,
          enableTapRecognizer: true,
        ),
      ),
    );
  }
void _onArCoreViewCreated(ArCoreController controller) {
    arCoreController = controller;
    _addEntityNode(arCoreController);
  }

void _addEntityNode(ArCoreController controller) {
    final entityNode = ArCoreReferenceNode(
        name: entity,
        objectUrl:
        "${objectKeys[entity.toLowerCase()]["3d_model_URI"]}",
        position: vector.Vector3(
          0, 0, -1
        ),
    );

    arCoreController.addArCoreNode(entityNode);
/*below code is for making the execution sleep for 10 seconds so you can see the node
initialize and then disappear after ten seconds. The main part to note is the removeNode
function*/ 
    await Future.delayed(const Duration(seconds: 10));
    arCoreController.removeNode(entityNode);
  }

顺便说一句,我们拥有相同的用户名真是个奇迹,哈哈