博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ARKit从入门到精通(6)-ARSession介绍
阅读量:6871 次
发布时间:2019-06-26

本文共 2430 字,大约阅读时间需要 8 分钟。

  • 转载: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 
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
@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
@optional /** 相机当前状态(ARFrame:空间位置,图像帧等)更新 */ - (void)session:(ARSession *)session didUpdateFrame:(ARFrame *)frame; /** 添加锚点 */ - (void)session:(ARSession *)session didAddAnchors:(NSArray
*)anchors; /** 刷新锚点 */ - (void)session:(ARSession *)session didUpdateAnchors:(NSArray
*)anchors; /** 移除锚点 */ - (void)session:(ARSession *)session didRemoveAnchors:(NSArray
*)anchors; @end
你可能感兴趣的文章
Codevs 3304 水果姐逛水果街Ⅰ 线段树
查看>>
linux共享windows资料
查看>>
前端UI框架总结
查看>>
( component 标签元素,及其 :is 属性 )的使用样例(组件切换的一个简单样例,不过,最好使用动画来实现组件的切换)...
查看>>
这7个人生捷径,一定不要走!
查看>>
Koa2+Mysql搭建简易博客
查看>>
Atom 初识
查看>>
Servlet、Filter和Listener
查看>>
高中数学运算能力训练题【基础中阶高阶辅导】
查看>>
Bean的装配方式
查看>>
get_browser()用法
查看>>
期中考试
查看>>
windows下的vim安装使用
查看>>
HTML内容总结
查看>>
Python--day69--ORM的F查询和Q查询
查看>>
C++符号优先级
查看>>
js 倒计时功能源码
查看>>
(转)非常完善的Log4net详细说明
查看>>
C++风格与C风格文件读写效率测试-vs2015,vs2017
查看>>
医道官途
查看>>