iOS 11 SceneKit hitTest:options: fails

无人久伴 提交于 2019-12-22 13:46:49

问题


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

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.

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.

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.

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.

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.

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.


回答1:


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
}


来源:https://stackoverflow.com/questions/46352867/ios-11-scenekit-hittestoptions-fails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!