arcore_flutter_plugin icon indicating copy to clipboard operation
arcore_flutter_plugin copied to clipboard

onPlaneTap returns empty list

Open sayurikunugi opened this issue 4 years ago • 5 comments

Hello. Thank you for the great plugin. I ran the example folder project, almost everything worked fine, except for detecting taps. Custom Anchored Object with onTap page, no objects shown when I tapped the camera screen.

I added below log in _CustomObjectState. _handleOnPlaneTap, and the result of hits?.length was 0.

  void _handleOnPlaneTap(List<ArCoreHitTestResult> hits) {
    print('CustomObject:_handleOnPlaneTap[in]${hits?.length}');
    final hit = hits.first;

How does it supposed to show the object? Thank you in advance.

sayurikunugi avatar Dec 09 '20 03:12 sayurikunugi

@sayurikunugi If no plane is detected, hits will be zero, like you said. So you need this: if (hits.isNotEmpty) { final hit = hits.first; [...] }

wiizarrrd avatar May 04 '21 13:05 wiizarrrd

@wiizarrrd I tried to see a variety of surroundings but then also it always keep showing hits as empty array. Do you have any idea?

studcroc avatar Nov 18 '21 08:11 studcroc

@hvg2416 Did you use the following code?

ArCoreView( onArCoreViewCreated: _onArCoreViewCreated, enableTapRecognizer: true, )

void _onArCoreViewCreated(ArCoreController controller) { arCoreController = controller; arCoreController.onNodeTap = (name) => onTapHandler(name); arCoreController.onPlaneTap = _handleOnPlaneTap; }

wiizarrrd avatar Nov 18 '21 23:11 wiizarrrd

@wiizarrrd yes. I am attaching my code below as well for reference.

import 'dart:developer';

import 'package:arcore_flutter_plugin/arcore_flutter_plugin.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:vector_math/vector_math.dart' as vector;

class ArCoreExample extends StatefulWidget {
  const ArCoreExample({Key? key}) : super(key: key);

  @override
  State<ArCoreExample> createState() => _ArCoreExampleState();
}

class _ArCoreExampleState extends State<ArCoreExample> {
  ArCoreController? arCoreController;

  void onTapHandler(String name) {
    log(name, name: 'DEBUG');
  }

  void _onPlaneTapHandler(List<ArCoreHitTestResult> hits) {
    log(hits.toString(), name: 'DEBUG');
    final hit = hits.first;

    final moonMaterial = ArCoreMaterial(color: Colors.grey);

    final moonShape = ArCoreSphere(
      materials: [moonMaterial],
      radius: 0.03,
    );

    dynamic vector3 = vector.Vector3(0.2, 0, 0);
    dynamic vector4 = vector.Vector4(0, 0, 0, 0);

    final moon = ArCoreNode(
      shape: moonShape,
      position: vector3,
      rotation: vector4,
    );

    final earthMaterial = ArCoreMaterial(
      color: const Color.fromARGB(120, 66, 134, 244),
    );

    final earthShape = ArCoreSphere(
      materials: [earthMaterial],
      radius: 0.1,
    );

    final earth = ArCoreNode(
        shape: earthShape,
        children: [moon],
        position: hit.pose.translation,
        rotation: hit.pose.rotation);

    arCoreController?.addArCoreNodeWithAnchor(earth);
  }

  @override
  Widget build(BuildContext context) {
    void _onArCoreViewCreated(ArCoreController controller) {
      arCoreController = controller;
      arCoreController!.onNodeTap = (name) => onTapHandler(name);
      arCoreController!.onPlaneTap = _onPlaneTapHandler;
    }

    return ArCoreView(
      onArCoreViewCreated: _onArCoreViewCreated,
      enableTapRecognizer: true,
    );
  }
}

studcroc avatar Nov 19 '21 08:11 studcroc

Any update on this?

vishaldhaduk9986 avatar Jun 03 '24 11:06 vishaldhaduk9986