CariusLars / ar_flutter_plugin

Flutter Plugin for AR (Augmented Reality) - Supports ARKit on iOS and ARCore on Android devices
MIT License
322 stars 233 forks source link

onNodeTap callback work only when node name has [#" prefix (iOS only) #104

Open OnixFlutterTeam opened 2 years ago

OnixFlutterTeam commented 2 years ago

Hi there. Not sure is this an issue but I faced this during development. Simple app: add node and handle tap on it.

Android: All Work Fine. iOS: Tap on Node not working. (No any events in callback).

My code:

AR View

 ARView(
              onARViewCreated: _onARViewCreated,
              planeDetectionConfig: PlaneDetectionConfig.none,
            )

Create ArView created:

      ARSessionManager arSessionManager,
      ARObjectManager arObjectManager,
      ARAnchorManager arAnchorManager,
      ARLocationManager arLocationManager) {
    _arSessionManager = arSessionManager;
    _arObjectManager = arObjectManager;

    arSessionManager.onInitialize(
      handleTaps: true,
      showAnimatedGuide: false,
      showPlanes: false,
      showFeaturePoints: false,
      showWorldOrigin: false,
    );
    _arObjectManager.onInitialize();
    _addLocalNode();
  }

Adding node:

 Future<void> _addLocalNode() async {
    var newNode = ARNode(
      type: NodeType.localGLTF2,
      uri: "assets/model/Chicken_01.gltf",
      name: _arPlaneNode,
      scale: Vector3(0.1, 0.1, 0.1),
      position: Vector3(1, 1, 0.8),
    );

    var didAddLocalNode = await _arObjectManager.addNode(newNode);

    if (didAddLocalNode ?? false) {
      _arObjectManager.onNodeTap = _handleOnNodeTap;
    } 
  }

Callback:

 Future<void> _handleOnNodeTap(List<String> nodes) async {
    print('NodeTapped! ${nodes.join('\n')}');
  }

So Android works fine. But! IOS works too - but I need to add [#" to node name as prefix.
For example: final String _arPlaneNode = '[#"ar_plane_node';

Not sure is it a bug but this not described anywhere (if not just close it), just discovered way to fix taps digging iOS code...

Koobonik commented 2 years ago

In my case I use a function to remove it.

String removeIosSharp(String str){ String nodeFirst; if(str.startsWith("[#") && str.endsWith("]")){ nodeFirst = str.substring(2, str.length - 1); } else { nodeFirst = str; } return nodeFirst; }