在ARKit和RealityKit中使用Raycast的真正好处是什么? [英] What is the real benefit of using Raycast in ARKit and RealityKit?

查看:340
本文介绍了在ARKit和RealityKit中使用Raycast的真正好处是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ARKit和RealityKit中的光线投射有什么作用?

What is a ray-casting in ARKit and RealityKit for?

当我需要使用 makeRaycastQuery 实例方法时:

And when I need to use a makeRaycastQuery instance method:

func makeRaycastQuery(from point: CGPoint, 
                 allowing target: ARRaycastQuery.Target, 
                       alignment: ARRaycastQuery.TargetAlignment) -> ARRaycastQuery?

任何帮助表示赞赏.

推荐答案

简单的Ray-CastingHit-Testing相同,通过从屏幕点投射虚构的射线来帮助在真实表面上找到3D位置. .我在Apple文档中找到了射线投射的以下定义:

Simple Ray-Casting, the same way as Hit-Testing, helps find a 3D position on a real-world surface by projecting an imaginary ray from a screen point. I've found a following definition of ray-casting in Apple documentation:

射线投射是在现实环境中查找表面上位置的首选方法,但是为了兼容性,命中测试功能仍然存在.通过跟踪射线广播,ARKit继续完善结果,以提高通过射线广播放置的虚拟内容的位置准确性.

Ray-casting is the preferred method for finding positions on surfaces in the real-world environment, but the hit-testing functions remain present for compatibility. With tracked ray-casting, ARKit continues to refine the results to increase the position accuracy of virtual content you place with a ray-cast.

当用户想要将虚拟内容放置在某个表面上时,为此提示一个好主意.许多AR应用程序会绘制一个焦点圆或正方形,以使用户可以视觉确认ARKit知道的曲面的形状和对齐方式.因此,要找出在现实世界中放置焦点圆或正方形的位置,可以使用ARRaycastQuery来询问ARKit现实世界中任何表面存在的地方.

When the user wants to place a virtual content onto some surface, it's a good idea to have a tip for this. Many AR apps draw a focus circle or square that give the user visual confirmation of the shape and alignment of the surfaces that ARKit is aware of. So, to find out where to put a focus circle or a square in the real world, you may use an ARRaycastQuery to ask ARKit where any surfaces exist in the real world.

这是一些抽象的示例,您可以在其中看到射线投射方法makeRaycastQuery():

Here's some abstract example where you could see ray-casting method makeRaycastQuery():

import RealityKit

class ViewController: UIViewController {

    @IBOutlet var arView: ARView!
    let model = try! Entity.load(named: "car")

    func rayCastingMethod() {

        // target iOS 13.0+, Xcode 11.0+

        guard let query = arView.makeRaycastQuery(from: arView.center,
                                              allowing: .estimatedPlane,
                                             alignment: .vertical) 
        else {
            return
        }

        guard let result = arView.session.raycast(query).first 

        else {
            return
        }

        let transform = Transform(matrix: result.worldTransform)
        model.transform = transform

        let raycastAnchor = AnchorEntity(raycastResult: result)
        raycastAnchor.addChild(model)
        arView.scene.anchors.append(raycastAnchor)
    }
}

如果您想知道如何在RealityKit中使用Hit-Testing方法,请阅读如果您想知道如何在RealityKit中使用Convex-Ray-Casting方法,请阅读

If you want to know how to use a Convex-Ray-Casting methods in RealityKit, read THIS POST.

这篇关于在ARKit和RealityKit中使用Raycast的真正好处是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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