arcore_flutter_plugin
arcore_flutter_plugin copied to clipboard
onPlaneTap returns empty list
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 If no plane is detected, hits will be zero, like you said. So you need this: if (hits.isNotEmpty) { final hit = hits.first; [...] }
@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?
@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 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,
);
}
}
Any update on this?