ARKit 中的屏幕空间是什么意思? [英] What is mean by Screen space in ARKit?

查看:23
本文介绍了ARKit 中的屏幕空间是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我浏览第 805 节视频创建出色的 AR 体验时,他们提到在 AR 中显示文本时使用屏幕空间文本.他们使用了运行良好的 Measure 应用示例.

When I went through the video for session 805, Creating Great AR Experiences, and they mention using screen space text when displaying text in AR. They use the example of their Measure app that works quite well.

我想实现类似的功能.但是,我无法弄清楚.

I want to achieve similar functionality. But, I am not able to figure it out.

推荐答案

屏幕空间是显示器的 2D 像素坐标系.这是你通常做的事情,比如在屏幕空间中布置 UIKit 小部件等.

Screen Space is the 2D pixel coordinate system of your display. It's where you normally do things like laying out UIKit widgets in screen space, etc.

屏幕空间的替代方案是 3D 坐标空间,它与 ARKit 的 3D 世界跟踪或用于在 AR 中显示虚拟 3D 内容的 3D 渲染引擎相关.(在这种情况下,需要考虑多个 3D 空间,例如绝对"世界空间与相机相对定位.)

The alternative to Screen Space is a 3D coordinate space that relates to the 3D world tracking ARKit does or the 3D rendering engine you use to display virtual 3D content in AR. (In that case there are multiple 3D spaces to consider, like "absolute" world space vs camera-relative positioning.)

如 WWDC18 演讲中所述创造出色的 AR 体验,屏幕空间是一种很好的方式来显示本质上是 2D 的内容(如文本),无论与内容相关联的现实世界特征的距离或方向如何,它都保持可读.(如果您将该文本标签放置在世界空间中,它会随着距离变远而变小且不可读.)

As mentioned in the WWDC18 talk Creating Great AR Experiences, screen space is a great way to display content that's inherently 2D (like text) in a way that remains readable regardless of the distance to or orientation of a real-world feature that content is associated with. (If you were to place that text label in world space, it'd get small and unreadable as you get far away.)

ARKit 没有为您提供任何让 2D 屏幕空间内容跟随 3D 世界空间位置的自动方式,但您自己实现这一点并不是特别困难.下面是按照 3D 位置叠加 UIView 的一般方法:

ARKit doesn't give you any automatic way to have 2D screen-space content follow a 3D world-space position, but making that happen yourself isn't especially difficult. Here's a general recipe for overlaying UIViews that follow 3D positions:

  1. 在您希望屏幕空间内容出现的实际位置添加 ARAnchor.
  2. 使用每帧回调(renderer(_:didUpdate:for:)renderer(_:updateAtTime:) 如果您使用带有 ARSCNView 的 SceneKit,session(_:didUpdate:)(如果您正在构建自己的渲染器)以获取该锚点的当前 3D 位置.
  3. 投影 3D 位置 (ARSCNView <代码>projectPoint, ARCamera projectPoint) 以获取该 3D 位置出现在屏幕上的 2D 点.
  4. 设置 UIView 的位置以匹配该点.
  1. Add an ARAnchor at the real-world position where you want screen-space content to appear.
  2. Use a per-frame callback (renderer(_:didUpdate:for:) or renderer(_:updateAtTime:) if you're using SceneKit with ARSCNView, session(_:didUpdate:) if you're building your own renderer) to get the current 3D position of that anchor.
  3. Project the 3D position (ARSCNView projectPoint, ARCamera projectPoint) to get the 2D point where that 3D position appears on screen.
  4. Set the position of your UIView to match that point.

对于更高级的情况,例如 Measure 应用程序如何使其屏幕空间标签与两个 3D 点之间的线平行,您需要投影两个端点并使用类似 atan2 的函数来获取旋转标签的角度.

For more advanced cases like how the Measure app makes its screen-space label parallel to the line between two 3D points, you'd need to project the two endpoints and use a function like atan2 to get an angle for rotating the label.

这篇关于ARKit 中的屏幕空间是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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