07-ARSession介绍

作者: 60916fc63567 | 来源:发表于2017-06-22 14:56 被阅读174次

7.1 概述###

ARSession是一个连接底层与AR视图之间的桥梁,其实ARSCNView内部所有的代理方法都是由ARSession来提供的。
ARSession与ARScnView之间的关系看起来是这样的:

image.png

7.2 ARSession获取相机位置数据主要有两种方式###

第一种:push。 实时不断的获取相机位置,由ARSession主动告知用户。通过实现ARSession的代理-
(void)session:(ARSession *)session didUpdateFrame:(ARFrame *)frame来获取
第二种:pull。 用户想要时,主动去获取。ARSession的属性currentFrame来获取

7.3 API介绍(swift版本):###

<pre>
import ARKit

extension ARSession {

/**回话断开重连时的行为
 Set of options for running the session.
 @discussion These options alter the behavior of calling run on a session.
 Providing no options will result in the default behavior of resuming tracking
 from the last known position and keeping all existing anchors.
 */
@available(iOS 11.0, *)
public struct RunOptions : OptionSet {

    public init(rawValue: UInt)

    
    /** The session will reset tracking.表示重置追踪 */
    public static var resetTracking: ARSession.RunOptions { get }

    
    /** The session will remove existing anchors. 移除现有锚点*/
    public static var removeExistingAnchors: ARSession.RunOptions { get }
}

}

/**
The ARSession class configures and runs different Augmented Reality techniques on a device.
*/
@available(iOS 11.0, *)
open class ARSession : NSObject {

/**
代理
 A delegate for receiving ARSession updates.
 */
weak open var delegate: ARSessionDelegate?


/**
 指定代理执行的线程(主线程不会有延迟,子线程会有延迟),不指定的话默认主线程 
 The dispatch queue on which the delegate calls are performed.
 @discussion If not provided or nil, delegate calls will be performed on the main queue.
 */
open var delegateQueue: DispatchQueue?


/**相机当前的位置、时间戳、视频帧信息(是由回话追踪配置计算出来的)
 The current frame of the session.
 */
@NSCopying open var currentFrame: ARFrame? { get }


/**会话追踪配置
 The configuration currently being used by the session.
 */
@NSCopying open var configuration: ARSessionConfiguration? { get }


/**运行会话
 Runs the session with the provided configuration and options.
 @discussion Calling run on a session that has already started will
 transition immediately to using the new session configuration. Options
 can be used to alter the default behavior when transitioning configurations.
 @param configuration The configuration to use.
 @param options The run options to use.
 */
open func run(_ configuration: ARSessionConfiguration, options: ARSession.RunOptions = [])


/**
 暂停回话
 Pauses the session.
 @discussion Once paused, no more updates will be received from the
 session until run is called again.
 */
open func pause()


/**
 添加锚点
 Adds an anchor to the session.
 @discussion The anchor will be added in the next frame update.
 @param anchor The anchor to add.
 */
open func add(anchor: ARAnchor)


/**
 移除锚点
 Removes an anchor from the session.
 @discussion The anchor will be removed from subsequent frame updates.
 @param anchor The anchor to remove.
 */
open func remove(anchor: ARAnchor)

}

@available(iOS 11.0, *)
public protocol ARSessionObserver : NSObjectProtocol {

/**
 This is called when a session fails.
session失败
 @discussion On failure the session will be paused.
 @param session The session that failed.
 @param error The error being reported (see ARError.h).
 */
optional public func session(_ session: ARSession, didFailWithError error: Error)


/**
 This is called when the camera's tracking state has changed.
 相机改变追踪状态
 @param session The session being run.
 @param camera The camera that changed tracking states.
 */
optional public func session(_ session: ARSession, cameraDidChangeTrackingState camera: ARCamera)


/**
 This is called when a session is interrupted.
 session意外断开(如果开启ARSession之后,APP退到后台就有可能导致回话断开)
 @discussion A session will be interrupted and no longer able to track when
 it fails to receive required sensor data. This happens when video capture is interrupted,
 for example when the application is sent to the background or when there are
 multiple foreground applications (see AVCaptureSessionInterruptionReason).
 No additional frame updates will be delivered until the interruption has ended.
 @param session The session that was interrupted.
 */
optional public func sessionWasInterrupted(_ session: ARSession)


/**
 This is called when a session interruption has ended.
 session会话断开恢复(短时间退到后台再进入APP会自动恢复)
 @discussion A session will continue running from the last known state once
 the interruption has ended. If the device has moved, anchors will be misaligned.
 To avoid this, some applications may want to reset tracking (see ARSessionRunOptions).
 @param session The session that was interrupted.
 */
optional public func sessionInterruptionEnded(_ session: ARSession)

}

@available(iOS 11.0, *)
public protocol ARSessionDelegate : ARSessionObserver {

/**
 This is called when a new frame has been updated.
 相机当前状态(ARFrame: 空间位置,图像帧等)更新
 @param session The session being run.
 @param frame The frame that has been updated.
 */
optional public func session(_ session: ARSession, didUpdate frame: ARFrame)


/**
 This is called when new anchors are added to the session.
 添加锚点
 @param session The session being run.
 @param anchors An array of added anchors.
 */
optional public func session(_ session: ARSession, didAdd anchors: [ARAnchor])


/**
 This is called when anchors are updated.
 刷新锚点
 @param session The session being run.
 @param anchors An array of updated anchors.
 */
optional public func session(_ session: ARSession, didUpdate anchors: [ARAnchor])


/**
 This is called when anchors are removed from the session.
 移除锚点
 @param session The session being run.
 @param anchors An array of removed anchors.
 */
optional public func session(_ session: ARSession, didRemove anchors: [ARAnchor])

}

</pre>

相关文章

  • 07-ARSession介绍

    7.1 概述### ARSession是一个连接底层与AR视图之间的桥梁,其实ARSCNView内部所有的代理方法...

  • Runtime介绍---术语介绍

    1. 什么是Runtime Runtime又叫运行时,是一套C语言的API。 我们平时编写的OC代码,底层都是基于...

  • 介绍

    万物终有一天会消失殆尽,诸神出卖黎明,光明为黑暗所湮灭,日月皆痕,海潮鸣泣,幼雏嚎啕,生灵涂炭。 托里奥世纪第20...

  • 介绍😊

    大家好,我是beth,初入简书,不邀自来,还请各位见谅! 先说说我是怎么想着来的吧?这不是刚过了一个寒假嘛...

  • 介绍

    在这个世界上还有三个家族他们不受各个国家联合国管。但他们身上有着使命分别是帝国家族曲国家族圣国家族。他们隐藏在一个...

  • 介绍

    云轩:主角,星罗帝国的二皇子。从小就不能练气,被人们称为废物。直到12岁的时候,自己的武魂觉醒才能练气,双...

  • 介绍

    万花阁 神秘至极的组织,亦正亦邪。万花阁的人行动隐秘,至今未被发现所在地。听说组成成员均以花来命名。所到之处,皆留...

  • 介绍

    此书命曰元.八洲传。属九洲四传第二部。第一部,上古往事。上古往事乃元八洲传外传。前两部为战胜心魔,而第三部,大梦...

  • 介绍

    千肆篇 7月的天气燥热,但在红杏阁里这份燥热就别有一番风味。漫天的胭脂水粉的香味变成了调味剂,女人们千姿百媚,在...

  • 介绍

    该文集属于收录文集,里面的内容不全是本人创作,有收录个人喜欢的内容。 *(偏个人向)

网友评论

  • 751fc49dcbfd:push pop 后回来页面相机没反应了 你会有这种情况吗

本文标题:07-ARSession介绍

本文链接:https://www.haomeiwen.com/subject/nzrfcxtx.html