Positioning ArCoreNode objects with plane.pose.translations

I’m trying to follow some blog for creating an AR application with flutter. This is the part of the code which creates a sphere:

 void _addSphere(ArCoreController controller) {
    final material = ArCoreMaterial(
      color: Color.fromARGB(255, 66, 134, 244),
    );
    final sphere = ArCoreSphere(
      materials: [material],
      radius: 0.1,
    );
    final node = ArCoreNode(
      shape: sphere,
      position: plane.pose.translation + vector.Vector3(0, 0, -1.5),
    );
    controller.addArCoreNodeWithAnchor(node);
  }

As I expected the line plane.pose.translation gives me an error since plane isn’t defined anywhere in the code. I searched hard for how to initiate the plane variable, like maybe it is a package that you need to import, like the vector package:

import 'package:vector_math/vector_math_64.dart' as vector;

But I can’t find anything. Can someone help me with this?

In the example Project, I can see only the following imports:

import 'package:arcore_flutter_plugin/arcore_flutter_plugin.dart';
import 'package:flutter/material.dart';

And it’s used in this callback function:

  void _addToucano(ArCoreHitTestResult plane) {
    if (objectSelected != null) {
      //"https://github.com/KhronosGroup/glTF-Sample-Models/raw/master/2.0/Duck/glTF/Duck.gltf"
      final toucanoNode = ArCoreReferenceNode(
          name: objectSelected,
          object3DFileName: objectSelected,
          position: plane.pose.translation,
          rotation: plane.pose.rotation);

      arCoreController.addArCoreNodeWithAnchor(toucanoNode);
    } else {
      showDialog<void>(
        context: context,
        builder: (BuildContext context) =>
            AlertDialog(content: Text('Select an object!')),
      );
    }
  }

If you check where it;s called, then you will come across this:

  void _handleOnPlaneTap(List<ArCoreHitTestResult> hits) {
    final hit = hits.first;
    _addToucano(hit);
  }

Hope this helps. Also found this medium article which will push you in the right direction.

2 Likes

Thanks for the answer, the error has gone now…however its replaced by a new problem.

The onNodeTap , onPlaneTap and onPlaneDetected don’t seem to work. There’s no error or anything, they just don’t work. In my onArViewCreated function, I added the controller.onNodeTap and the other 2 functions, but when I tap on my AR object, nothing happes(it should print a simple “Node pressed” statement in the console).

I would suggest you open an issue on the Github Repository of the plugin.