ARKit从入门到精通(6)-ARSession介绍

  • 转载:http://blog.csdn.net/u013263917/article/details/73157082

  • ARSession是一个连接底层与AR视图之间的桥梁,其实ARSCNView内部所有的代理方法都是由ARSession来提供的

  • ARSession与ARScnView之间的关系看起来是这样的:


0701.png
    • ARSession获取相机位置数据主要有两种方式

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

/** 代理 */ @property (nonatomic, weak) id <ARSessionDelegate> delegate; /** 指定代理执行的线程(主线程不会有延迟,子线程会有延迟),不指定的话默认主线程 */ @property (nonatomic, strong, nullable) dispatch_queue_t delegateQueue; /** 相机当前的位置(是由会话追踪配置计算出来的) */ @property (nonatomic, copy, nullable, readonly) ARFrame *currentFrame; /** 会话追踪配置 */ @property (nonatomic, copy, nullable, readonly) ARSessionConfiguration *configuration; /** 运行会话(这行代码就是开启AR的关键所在) */ - (void)runWithConfiguration:(ARSessionConfiguration *)configuration NS_SWIFT_UNAVAILABLE("Use run(_:options:)"); /** 运行会话,只是多了一个参数ARSessionRunOptions:作用就是会话断开重连时的行为。ARSessionRunOptionResetTracking:表示充值追踪 ARSessionRunOptionRemoveExistingAnchors:移除现有锚点 */ - (void)runWithConfiguration:(ARSessionConfiguration *)configuration options:(ARSessionRunOptions)options NS_SWIFT_NAME(run(_:options:)); /** 暂停会话 */ - (void)pause; /** 添加锚点 */ - (void)addAnchor:(ARAnchor *)anchor NS_SWIFT_NAME(add(anchor:)); /** 移除锚点 */ - (void)removeAnchor:(ARAnchor *)anchor NS_SWIFT_NAME(remove(anchor:)); @end //session代理分类两部分,一个是观察者(KVO) 一个是委托者(代理) #pragma mark - ARSessionObserver //session KVO观察者 @protocol ARSessionObserver <NSObject> @optional /** session失败 */ - (void)session:(ARSession *)session didFailWithError:(NSError *)error; /** 相机改变追踪状态 */ - (void)session:(ARSession *)session cameraDidChangeTrackingState:(ARCamera *)camera; /** session意外断开(如果开启ARSession之后,APP退到后台就有可能导致会话断开) */ - (void)sessionWasInterrupted:(ARSession *)session; /** session会话断开恢复(短时间退到后台再进入APP会自动恢复) */ - (void)sessionInterruptionEnded:(ARSession *)session; @end #pragma mark - ARSessionDelegate @protocol ARSessionDelegate <ARSessionObserver> @optional /** 相机当前状态(ARFrame:空间位置,图像帧等)更新 */ - (void)session:(ARSession *)session didUpdateFrame:(ARFrame *)frame; /** 添加锚点 */ - (void)session:(ARSession *)session didAddAnchors:(NSArray<ARAnchor*>*)anchors; /** 刷新锚点 */ - (void)session:(ARSession *)session didUpdateAnchors:(NSArray<ARAnchor*>*)anchors; /** 移除锚点 */ - (void)session:(ARSession *)session didRemoveAnchors:(NSArray<ARAnchor*>*)anchors; @end

转载于:https://www.cnblogs.com/sunfuyou/p/7792495.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值