ARKit:如何使HitTest命中SCNNode? [英] ARKit : how to get a SCNNode hit by hitTest?

查看:193
本文介绍了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

问题是我没有得到可靠的结果.当我单击一个平面时,结果数组始终包含一个对象,但它并不总是一个Plane对象(也不是其父对象),而只是一个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,指定点击测试搜索应该针对节点的几何形状进行测试.为此选项指定是"会提高搜索性能,但会降低几何精度.

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

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

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