A shared object that manages the device camera and motion processing needed for augmented reality experiences.
管理增强现实体验所需的设备摄像头和运动处理的共享对象。
Overview
AnARSessionobject coordinates the major processes that ARKit performs on your behalf to create an augmented reality experience. These processes include reading data from the device's motion sensing hardware, controlling the device's built-in camera, and performing image analysis on captured camera images. The session synthesizes all of these results to establish a correspondence between the real-world space the device inhabits and a virtual space where you model AR content.
Every AR experience built with ARKit requires a singleARSessionobject. If you use anARSCNVieworARSKViewobject to easily build the visual part of your AR experience, the view object includes anARSessioninstance. If you build your own renderer for AR content, you'll need to instantiate and maintain anARSessionobject yourself.
Running a session requires a session configuration: an instance of theARConfigurationclass, or its subclassARWorldTrackingConfiguration. These classes determine how ARKit tracks a device's position and motion relative to the real world, and thus affect the kinds of AR experiences you can create.
概述
ARSession对象负责协调ARKit代表您创建增强现实体验的主要流程。 这些过程包括从设备的运动传感硬件读取数据,控制设备的内置摄像头以及对捕获的摄像头图像执行图像分析。 会话综合所有这些结果,以建立设备处的真实世界空间与模拟AR内容的虚拟空间之间的对应关系。
使用ARKit构建的每个AR体验需要一个ARSession对象。 如果您使用ARSCNView或ARSKView对象轻松构建AR体验的可视部分,则视图对象包含ARSession实例。 如果您为AR内容构建自己的渲染器,则需要自行实例化和维护ARSession对象。
运行会话需要一个会话配置:ARConfiguration类的一个实例,或其子类ARWorldTrackingConfiguration。 这些类将决定ARKit如何跟踪设备相对于真实世界的位置和运动,从而影响您可以创建的AR体验种类。
主要的
Configuring and Running a Session
- runWithConfiguration:options:
Starts AR processing for the session with the specified configuration and options.
- runWithConfiguration:options:
使用指定的配置和选项为Session启动AR处理。
Parameters
configuration
An object that defines motion and scene tracking behaviors for the session.
options
Options affecting how existing session state (if any) transitions to the new configuration.
If the session is running for the first time, this parameter has no effect.
参数
组态
定义Session的运动和场景跟踪行为的对象。
选项
影响现有Session状态(如果有)如何转换到新配置的选项。
如果会话第一次运行,则此参数不起作用。
Discussion
The session tracks device motion, captures and processes scene imagery from the device camera, and coordinates with yourdelegateobject orARSCNVieworARSKViewview only when running.
Calling this method on a session that has already started transitions immediately to the new session configuration. Theoptionsparameter determines how existing session state transitions to the new configuration. By default, the session resumes device position tracking from the last known state and keeps any anchors you've added the session. After you call this method, the session runs asynchronously.
讨论
Session跟踪设备动作,捕捉和处理来自设备摄像头的场景图像,并且仅在运行时与您的委托对象或ARSCNView或ARSKView视图进行协调。
在已经开始的Session上调用此方法会立即转换为新的会话配置。 options参数确定现有Session状态如何转换到新配置。 默认情况下,Session从最后一个已知状态中恢复设备位置跟踪,并保留您添加Session的任何锚点。 调用此方法后,Session异步运行。ARSession对象负责协调ARKit代表您创建增强现实体验的主要流程。 这些过程包括从设备的运动传感硬件读取数据,控制设备的内置摄像头以及对捕获的摄像头图像执行图像分析。Session综合所有这些结果,以建立设备处的真实世界空间与模拟AR内容的虚拟空间之间的对应关系。
ARSessionRunOptions
Options affecting how to transition an AR session's current state when you change its configuration.
影响如何在更改配置时转换AR会话的当前状态的选项。
Topics
Options
ARSessionRunOptionResetTracking
The session does not continue device position/motion tracking from the previous configuration.
ARSessionRunOptionRemoveExistingAnchors
Any anchor objects associated with the session in its previous configuration are removed.
主要的
选项:
ARSessionRunOptionResetTracking
Session不会继续从以前的配置中进行设备位置/动作跟踪。
ARSessionRunOptionRemoveExistingAnchors
任何与之前配置中的Session关联的锚点对象都将被删除。
configuration
An object that defines motion and scene tracking behaviors for the session.
定义Session的运动和场景跟踪行为的对象。
- pause
Pauses processing in the session.
在Session中暂停处理
Responding to AR Updates
delegate
An object you provide to receive captured video images and tracking information, or to respond to changes in session status.
您提供的对象,用于接收捕获的视频图像和跟踪信息,或响应Session状态的更改。
Discussion
If you use theARSCNVieworARSKViewclass to display your AR experience, a session delegate isn't necessary. Those views automatically display captured video images and coordinate SceneKit or SpriteKit content to track device and camera motion.
If you create your own visualization for an AR experience using Metal or other rendering technologies, set a session delegate. Your delegate object periodically receivesARFrameobjects captured by the session. These objects contain video frame images for you to display and AR scene information you can use to coordinate display of the scene elements you render.
讨论
如果您使用ARSCNView或ARSKView类来显示AR体验,则不需要Session委托。 这些视图自动显示捕获的视频图像并协调SceneKit或SpriteKit内容以跟踪设备和相机的运动。
如果您使用Metal或其他渲染技术为AR体验创建自己的可视化文件,请设置Session代理。 您的委托对象会定期收到Session捕获的ARFrame对象。 这些对象包含要显示的视频帧图像和AR场景信息,您可以使用它们来协调显示您渲染的场景元素。
delegateQueue
The dispatch queue through which the session calls your delegate methods.
Session通过其调用委托方法的调度队列。
Discussion
If this value isnil(the default), the session calls your delegate methods on the main queue.
讨论
Session通过其调用委托方法的调度队列。
ARSessionDelegate
Methods you can implement to receive captured video frame images and tracking state from an AR session.
您可以实现它以从AR Session中接收捕获的视频帧图像和跟踪状态的方法。继承自ARSessionObserver。
Overview
Implement this protocol if you need to work directly withARFrameobjects captured by the session or directly follow changes to the session's set of trackedARAnchorobjects. Typically, you adopt this protocol when building a custom view for displaying AR content—if you display content with SceneKit or SpriteKit, theARSCNViewDelegateandARSKViewDelegateprotocols provide similar information and integrate with those technologies.
This protocol extends theARSessionObserverprotocol, so your session delegate can also implement those methods to respond to changes in session status.
概述
如果您需要直接处理由会话捕获的ARFrame对象,或者直接跟踪会话的一组跟踪的ARAnchor对象的更改,请实施此协议。 通常,在构建用于显示AR内容的自定义视图时采用此协议 - 如果使用SceneKit或SpriteKit显示内容,则ARSCNViewDelegate和ARSKViewDelegate协议提供类似的信息并与这些技术集成。
该协议扩展了ARSessionObserver协议,因此您的会话委托也可以实现这些方法来响应会话状态的变化。
Topics
Receiving Camera Frames
session:didUpdateFrame:
Provides a newly captured camera image and accompanying AR information to the delegate.
向代表提供新捕获的摄像机图像和伴随的AR信息。
Handling Content Updates
session:didAddAnchors:
Tells the delegate that one or more anchors have been added to the session.
告诉代表已将一个或多个锚点添加到Session中。
session:didUpdateAnchors:
Tells the delegate that the session has adjusted the properties of one or more anchors.
告诉代表该会话已调整了一个或多个锚点的属性。
session:didRemoveAnchors:
Tells the delegate that one or more anchors have been removed from the session.
告诉代表已经从会话中删除了一个或多个锚点。
Inherits From
ARSessionObserver
ARSessionObserver
Methods you can implement to respond to changes in the state of an AR session.
您可以实施的方法来响应AR会话状态的变化。
Displaying and Interacting with AR Content
currentFrame
The video frame image, with associated AR scene information, most recently captured by the session.
最近由Session捕获的视频帧图像与相关的AR场景信息。
- addAnchor:
Adds the specified anchor to be tracked by the session.
添加由会话跟踪的指定锚点。捕获下一帧时,锚点跟踪的更改会生效。
- removeAnchor:
Removes the specified anchor from tracking by the session.
删除会话跟踪指定的锚点。捕获下一帧时,锚点跟踪的更改会生效。
Updating the World Origin
- setWorldOrigin:
Changes the basis for the AR world coordinate space using the specified transform.
使用指定的变换更改AR世界坐标空间的基础。
Parameters
relativeTransform
A transform matrix encoding a translation and orientation relative to the session's current world coordinate space.
参数
relativeTransform
一个转换矩阵,用于编译相对于Session当前世界坐标空间的转换和方向。
Discussion
ARKit defines a world coordinate space for you to use to place virtual content and locate detected objects in an AR experience. By default, this space is based on the initial position and orientation of the device when the session begins. However, after a session begins and has detected useful reference points (such as a plane or image), you may find it helpful to redefine the world coordinate system based on those reference points.
讨论
ARKit为您定义了一个世界坐标空间,用于放置虚拟内容并在AR体验中定位检测到的对象。 默认情况下,此空间基于Session开始时设备的初始位置和方向。 但是,在Session开始并检测到有用的参考点(例如平面或图像)之后,您可能会发现根据这些参考点重新定义世界坐标系会很有帮助。
Instance Methods
Instance Methods
- runWithConfiguration:
网友评论