是否可以在没有平面检测的情况下通过命中测试放置对象? [英] Is it possible to place objects with hit test without plane detection?

查看:19
本文介绍了是否可以在没有平面检测的情况下通过命中测试放置对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循 Apple 的

此外,命中测试在 3D 游戏中被积极使用,但它更适合 VR 而不是 AR.

Following Apple's Creating an Immersive AR Experience with Audio , I thought it would be interesting to experiment and try to place objects anywhere and not just on a vertical and horizontal plane. Is it at all possible to place an object using touch without plane detection? I understand that plane detection would increase the accuracy of hit tests and ARAnchor detection, so would there be any way where one could perform hit tests on any other location in the scene?

解决方案

If your AR scene already contains any 3D geometry in a current session you can definitely use hit-testing to place a new model there (a placement based on already contained 3D geometry), or you can use feature points for model's placement (if any).

If there's no 3D geometry at all in your AR scene, or there's a extremely sparse point cloud, what do you apply hit-testing method to? Hit-test is a projected 2D point from screen-space onto a 3D surface (remember, detected planes are hidden 3D planes), or onto any appropriate feature point.

So, in AR, plane detection is crucial when developer is using hit-testing.

func hitTest(_ point: CGPoint, 
               types: ARHitTestResult.ResultType) -> [ARHitTestResult]

Here you can see all the ARHitTestResult.ResultType available.

But pay attention to this, there's a hitTest method returning SCNHitTestResult:

func hitTest(_ point: CGPoint, 
             options: [SCNHitTestOption : Any]?) -> [SCNHitTestResult]

Usage:

let touchPosition: CGPoint = gesture.location(in: sceneView)

let hitTestResult = sceneView.hitTest(touchPosition, 
                                      types: .existingPlaneUsingExtent)

or:

let hitTestResult = sceneView.hitTest(touchPosition, 
                                      types: .featurePoint)

Also, hit-testing is actively used in 3D games but it's rather for VR there than for AR.

这篇关于是否可以在没有平面检测的情况下通过命中测试放置对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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