ARKit:如何通过 hitTest 获得 SCNNode 命中? [英] ARKit : how to get a SCNNode hit by hitTest?

查看:35
本文介绍了ARKit:如何通过 hitTest 获得 SCNNode 命中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个平面被 ARKit 检测到并且对用户可见.

I have several planes detected by ARKit and made visible to the user.

我希望用户能够点击屏幕以仅保留他选择的平面,更改其颜色并删除其他平面.

I want the user to be able to click on the screen in order to keep only the plane he selected, change its color and delete the other ones.

我的飞机被添加到 didAddNode 委托方法中,如下所示:

My planes are added in the didAddNode delegate method like this:

 Plane *plane = [[Plane alloc] initWithAnchor: (ARPlaneAnchor *)anchor];
    [self.planes setObject:plane forKey:anchor.identifier];

在另一种方法中,我捕捉到用户的点击并希望能够改变他选择的平面的颜色并删除其他平面.

In another method, I catch the click of the user and want to be able to change the color of the plane he selected and delete the other ones.

这是我写的:

 CGPoint holdPoint = [recognizer locationInView:self.sceneView];

    NSArray<SCNHitTestResult *> *result = [self.sceneView hitTest:holdPoint
                                                              options:@{SCNHitTestBoundingBoxOnlyKey: @YES, SCNHitTestFirstFoundOnlyKey: @YES}]; 

        if (result.count == 0) {
                    return;
        }

        SCNHitTestResult * hitResult = [result firstObject];

 SCNNode *node = hitResult.node;

 SCNNode *parentNode = node.parentNode; // the geometry being child of my Plane object

问题是我没有得到可靠的结果.当我点击一个平面时,结果数组总是包含一个对象,但它并不总是一个平面对象(既不是它的父对象),而只是一个 SCNNode.

The problem is that I don't get a reliable result. The result array always contains one single object when I click on a plane but it is not always a Plane object (neither its parent), but just a SCNNode.

发生了什么?如何解决这个问题呢 ?

What is happening ? How to solve this problem ?

如果您有任何代码可以检测其他平面中某个平面上的点击,我很感兴趣!

If you have any code working to detect a click on a plane among other planes, I am interested !

推荐答案

如果你想要完美的结果,你使用的选项似乎过于宽松

The options you use seem too permissive if you want perfect results

SCNHitTestBoundingBoxOnlyKey 默认值为NO,指定命中测试搜索应该针对节点几何进行测试.为该选项指定 YES 可提高搜索性能以牺牲几何精度为代价.

SCNHitTestFirstFoundOnlyKey 默认值为NO,指定命中测试应该返回找到的所有对象.如果您指定 YES,则命中测试结果数组仅包含找到的第一个对象(不一定是最近的).

这篇关于ARKit:如何通过 hitTest 获得 SCNNode 命中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆