ARSession 委托方法之间有什么区别?
我正在制作一个 Swift 应用程序,目前该应用程序使用 ARImageAnchor
和 ARReferenceImage
将一些简单的形状放置到参考图像上。现在,所有增强内容都被放置在 session(_:didAdd:)
函数中,但我知道还有一个 session(_:didUpdate:)
功能。 didAdd
版本很有意义,因为它仅在添加锚点时运行。但是苹果文档对于第二个版本的确切目的有点模糊:
func session(ARSession, didUpdate: [ARAnchor])
// Tells the delegate that the session has adjusted
// the properties of one or more anchors.
这是否意味着只要锚点在场景中移动,这个函数就会运行?或者“属性”指的不仅仅是锚点的位置?我只是有点困惑第二个函数的用途。
I am in the process of making a Swift app that currently places some simple shapes onto a reference image using an ARImageAnchor
and an ARReferenceImage
. Right now, all of the augmented content is being placed within the session(_:didAdd:)
function, however I know there is also a session(_:didUpdate:)
function. The didAdd
version makes sense, since it just runs when an anchor is added. But the Apple documentation is a bit vague about the exact purpose of this second version:
func session(ARSession, didUpdate: [ARAnchor])
// Tells the delegate that the session has adjusted
// the properties of one or more anchors.
Does this mean any time the anchors move within the scene this function will run? Or is "properties" referring to something other than just the position of the anchors? I am just a bit confused what this second function would be used for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

前言
我同意你的观点,Apple 的文档常常不清楚。
ARKit 和/或 RealityKit 应用程序构建在正在运行的 ARSession 对象上,该对象是基于特定 配置。 ARKit 中的每种配置类型都允许您生成特定的 ARAnchors (
ARPlaneAnchor
、ARImageAnchor
、ARFaceAnchor
等)。在 ARKit 中,我们必须使用显式(手动)配置,而在 RealityKit 中,配置是自动的,因为它是根据 AnchorEntity 类型(.plane
、.image< /code>、
.face
等)。ARKit 锚点可以通过实现 session(...) 或 renderer(...) 委托方法。 ARKit 锚点可以通过每个 ARFrame(每秒 60 帧)访问。
RealityKit 锚点由应用程序自动(隐式)跟踪。 RealityKit 主播的集合可以通过场景访问目的。
ARKit 和 RealityKit 框架可以一起工作,也可以单独工作。 RealityKit 的 AnchorEntity 能够使用 ARKit 的 ARAnchor 转换将模型放入场景中:
用例
ARSessionDelegate 协议有 4 个可选的
session(...)
可以与这两个框架一起使用的方法。第一对session(...)
方法经常使用。session(_:didAdd:)
实例方法用于添加
/提取
特定锚点到
/在某些条件下来自
ARSession。但是,session(_:didUpdate:)
实例方法允许您根据特定 ARAnchor 的数据更新内容。可以通过以下方式完成:此帖子向您展示如何同时使用这两种方法。
并阅读这篇文章 了解如何单独使用
session(_:didUpdate:)
方法。Foreword
I agree with you that Apple's documentation is often unclear.
ARKit and/or RealityKit apps are built on a running ARSession object that is a key AR element based on a specific configuration. Each configuration type in ARKit allows you to generate specific ARAnchors (
ARPlaneAnchor
,ARImageAnchor
,ARFaceAnchor
, etc). In ARKit, we must use an explicit (manual) configuration, while in RealityKit, a configuration is automatic, due to the fact it's set according to the AnchorEntity type (.plane
,.image
,.face
, etc).ARKit anchors can be tracked by implementing the session(...) or renderer(...) delegate methods. ARKit anchors may be accessed through each ARFrame (60 frames per second).
RealityKit anchors are automatically (implicitly) tracked by the application. RealityKit anchors' collection can be accessed through the Scene object.
The ARKit and RealityKit frameworks can work together or separately from each other. RealityKit's AnchorEntity is capable of using ARKit's ARAnchor transform to place a model into a scene:
Use case
ARSessionDelegate protocol has 4 optional
session(...)
methods that you can use with both frameworks. The first pair ofsession(...)
methods are used quite often.session(_:didAdd:)
instance method is used toadd
/extract
specific anchorsto
/from
an ARSession under certain conditions. However,session(_:didUpdate:)
instance method allows you to update the content, based on a specific ARAnchor's data. It can be accomplished this way:THIS POST shows you how to use both methods together.
And read this post to find out how to use
session(_:didUpdate:)
method alone.