iOS 11 SceneKit hitTest:options:失败 [英] iOS 11 SceneKit hitTest:options: fails

查看:45
本文介绍了iOS 11 SceneKit hitTest:options:失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS 11的SceneKit中使用hitTest:options:遇到困难的情况.

I'm facing a difficult situation using hitTest:options: in SceneKit on iOS 11.

在地图应用程序中,我有一个Terrain节点.使用hitTest:options:通过触摸屏幕,我很长时间就能在地形上发现一个点.在iOS 11上发布的二进制文件以及在iOS 10模拟器的Xcode 9编译二进制文件中,它仍然可以按预期工作.

In a maping application I have a terrain node. Using hitTest:options: I was able for long to spot a point on the terrain from a touch on the screen. It still work as expected with released binary on iOS 11, and also on Xcode 9 compiled binary for iOS 10 simulator.

但是,iOS 11 SDK上的iOS 11二进制文件提供了完全不完整的结果.从hitTest:options返回数组:可能不包含任何结果或太多.而且,在大多数情况下,没有结果是有效的.以下是说明这一点的图像.所有图像均来自没有隐藏节点的场景.

But iOS 11 binary on iOS 11 SDK gives totaly eratic results. Return array from hitTest:options: may contain no result or too many. Moreover, most of the time none of the results is valid. Here below are images to illustrate the point. All image are from a scene with no hidden node.

编辑:我今天使用hitTestWithSegmentFromPoint:toPoint:options:进行了测试,并且得到了错误的结果.

Edit: I made a test today using hitTestWithSegmentFromPoint:toPoint:options: and got false results also.

首先使用可运行的模拟器.

First with working simulator.

它显示了地形上的正常击中.击中点用红色球表示.由于其中心正好在地形上,因此它在地形中的插入量是一半.

It shows a normal hit on the terrain. The hit point is illustrated with a red ball. It is half inset in the terrain as its center is right on the terrain.

这两个图像显示了射线"穿过地形3次的情况.我们将3个命中点正确放置在地形上.第二个图像更改了视角以显示3个点.

These two images show a case where the "ray" cross the terrain 3 times. We got 3 hits all placed correctly on the terrain.The second image change the angle of view to show the 3 points.

现在失败的iOS 11情况:

Now the failing iOS 11 situation:

在这张图片上我们获得了一次成功,但它在两座山脉之间无处",而不是在地形上.

On this picture we got one hit but it is "nowhere" between the two mountains, not on the terrain.

最后两张图片显示了其他尝试,分别有4次和16次命中,全部都是蓝色",与地形无关.

The last two pictures show other attempts with 4 and 16 hits, all "in the blue" with no connection to the terrain.

有时候,匹配是远离"地形的,有时它们位于相机和地形之间.

Sometimes the hit are "away" past the terrain, sometimes they are between the camera and the terrain.

推荐答案

我在iOS 11上遇到了同样的问题.我的解决方案:

I was facing the same problem on iOS 11. My solution:

var hitTestOptions = [SCNHitTestOption.sortResults : NSNumber(value: true),
                      SCNHitTestOption.boundingBoxOnly : NSNumber(value: true)]

if #available(iOS 11.0, *) {
    hitTestOptions[SCNHitTestOption.searchMode] = SCNHitTestSearchMode.all.rawValue as NSNumber
}

这篇关于iOS 11 SceneKit hitTest:options:失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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