- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
什么是 RealityKit 和 ARKit 中的光线转换?
我什么时候需要使用 makeRaycastQuery实例方法?
func makeRaycastQuery(from point: CGPoint,
allowing target: ARRaycastQuery.Target,
alignment: ARRaycastQuery.TargetAlignment) -> ARRaycastQuery?
感谢任何帮助。
最佳答案
简单的 Ray-Casting
,与 Hit-Testing
的方式相同,通过从屏幕转换假想的光线来帮助定位真实世界表面上的 3D 点二维点到检测到的平面上。在 Apple 文档 (2019) 中,光线转换的定义如下:
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 raycasting
, ARKit and RealityKit continue to refine the results to increase the position's accuracy of virtual content you placed with a raycast.
当用户想要将虚拟内容放置到检测到的表面上时,最好为此提供提示。许多 AR 应用程序绘制一个焦点圆或正方形,让用户视觉确认 RealityKit 或 ARKit 知道的表面的形状和对齐方式。因此,要找出在现实世界中放置焦点圆圈或正方形的位置,您可以使用 ARRaycastQuery
询问框架在现实世界中存在任何表面的位置。
这是一个示例,您可以在其中了解如何实现 raycast(query)
实例方法:
import UIKit
import RealityKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
let model = try! Entity.loadModel(named: "usdzModel")
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.raycasting()
}
fileprivate func raycasting() {
guard let query = arView.makeRaycastQuery(from: arView.center,
allowing: .estimatedPlane,
alignment: .horizontal)
else { return }
guard let result = arView.session.raycast(query).first
else { return }
let raycastAnchor = AnchorEntity(world: result.worldTransform)
raycastAnchor.addChild(model)
arView.scene.anchors.append(raycastAnchor)
}
}
如果您想知道如何在 RealityKit 中使用 Convex-Ray-Casting
,请阅读 this post .
如果您想知道如何在 RealityKit 中使用 Hit-Testing
,请阅读 this post .
这是一个示例代码,您可以在其中了解如何在 SwiftUI 中实现光线转换逻辑:
import SwiftUI
import RealityKit
struct ContentView: View {
@State private var arView = ARView(frame: .zero)
var model = try! Entity.loadModel(named: "robot")
var body: some View {
ARViewContainer(arView: $arView)
.onTapGesture(count: 1) { self.raycasting() }
.ignoresSafeArea()
}
fileprivate func raycasting() {
guard let query = arView.makeRaycastQuery(from: arView.center,
allowing: .estimatedPlane,
alignment: .horizontal)
else { return }
guard let result = arView.session.raycast(query).first
else { return }
let raycastAnchor = AnchorEntity(world: result.worldTransform)
raycastAnchor.addChild(model)
arView.scene.anchors.append(raycastAnchor)
}
}
然后……
struct ARViewContainer: UIViewRepresentable {
@Binding var arView: ARView
func makeUIView(context: Context) -> ARView { return arView }
func updateUIView(_ uiView: ARView, context: Context) { }
}
附言
如果您要从头构建这两个应用变体中的任何一个(即不使用 Xcode AR 模板),请不要忘记启用 中的
标签。Privacy - Camera Usage Description
键信息
关于swift - 在 ARKit 和 RealityKit 中使用 Raycast 的真正好处是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56466773/
如果函数定义顺序不对,Jslint 将指出错误。 显然 jslint 是严格的,但我想知道将函数按顺序排列是否有任何好处。 我的意思是在调用它们之前定义它们。 最佳答案 函数定义(和 var 语句)被
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我注意到Flask tutorial涉及到点的使用。看起来它只是用于在本地创建一个轮子,这将使服务器上的设置变得更容易,但作为一个网络开发新手,我很好奇:是否有人真的会一路将他们的网站上传到像 PyP
我一直在阅读有关 jquery live event 的内容,但仍然有点困惑?使用它有什么好处? http://docs.jquery.com/Events/live 我知道它与绑定(bind)类似,
这是我的故事:我已将我的应用迁移到 AndroidX,因为我需要从网上找到的库中获取一些新功能。 问题:我目前遇到了一些问题,因为我现在需要为 Cordova 开发一个插件来实现该应用程序的一部分。
在使用 RAD 或一般不使用单元测试时使用依赖注入(inject)是否有任何好处? 最佳答案 是的,有以下几个好处: 减少依赖 减少依赖携带 更多可重用代码 更多可测试代码 更具可读性的代码 更多引用
我目前正在构建一个通过 MSI Windows Installer 分发的产品。我们的客户正在使用不同的形式(例如我们在他们自己的 MSI 中)集成该产品,使用 Bootstrap /链接器(如 Wi
有人声称 Scala 的类型系统是图灵完备的。我的问题是: 这有正式的证据吗? 简单的计算在 Scala 类型系统中会是什么样子? 这对 Scala 这种语言有什么好处吗?与没有图灵完备类型系统的语言
我开始尝试使用 React,我注意到我正在制作的简单应用程序全部使用 JS。我的 html 页面只是一个空的 body 标签! 所以我有几个问题,因为我是这个框架的新手。 我的整个应用程序应该基本上都
我们有一个相当大的基于 Windows 的 1.1 .NET 应用程序,我们正在考虑升级到 2.0。我们考虑更新的主要原因是我们可以利用 Visual Studio 2008 进行项目的持续开发,以及
我有一个页面,其中内置了基于 ajax 的分页。分页用于页面中的“评论”功能。根据 Google 的网站管理员博客,具有 rel="next"和 rel="prev"值有利于 SEO。 我在头部添加了
我是一名优秀的程序员,十分优秀!