ARKit从入门到精通(5)-ARScnView介绍

  • AR视图,在第一小节笔者介绍过,ARKit支持3D的AR场景和2D的AR场景,ARSCNView是3D的AR场景视图

  • API介绍

@interface ARSCNView : SCNView
/**代理*/
@property (nonatomic, weak, nullable) id delegate;
/**AR会话*/
@property (nonatomic, strong) ARSession *session;
/**场景*/
@property(nonatomic, strong) SCNScene *scene;
/**是否自动适应灯光*/
@property(nonatomic) BOOL automaticallyUpdatesLighting;
/**返回对应节点的锚点,节点是一个3D虚拟物体,它的坐标是虚拟场景中的坐标,而锚点ARAnchor是ARKit中现实世界的坐标。*/
- (nullable ARAnchor *)anchorForNode:(SCNNode *)node;
- (nullable SCNNode *)nodeForAnchor:(ARAnchor *)anchor;
- /**根据2D坐标点搜索3D模型,这个方法通常用于,当我们在手机屏幕点击某一个点的时候,可以捕捉到这一个点所在的3D模型的位置,至于为什么是一个数组非常好理解。手机屏幕一个是长方形,
point:2D坐标点(手机屏幕某一点)
ARHitTestResultType:
捕捉类型  点还是面
(NSArray *):追踪结果数组  详情见本章节ARHitTestResult类介绍数组的结果排序是由近到远*/
- (NSArray *)hitTest:(CGPoint)point types (ARHitTestResultType)types;
- @end
//代理
 #pragma mark - ARSCNViewDelegate
 //代理的内部实现了SCNSceneRendererDelegate:scenekit代理 和ARSessionObserver:ARSession监听
@protocol ARSCNViewDelegate 
@optional
/**自定义节点的锚点*/
- (nullable SCNNode *)renderer:(id )renderer nodeForAnchor:
(ARAnchor *)anchor;
/**当添加节点是会调用,我们可以通过这个代理方法得知我们添加一个虚拟物体到AR场景下的锚点(AR现实世界中的坐标)*/
- (void)renderer:(id )renderer didAddNode:(SCNNode *)node 
forAnchor:(ARAnchor *)anchor;
/**将要刷新节点*/
- (void)renderer:(id )renderer willUpdateNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor;
/**已经刷新节点*/
- (void)renderer:(id 
)renderer didUpdateNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor;
/**移除节点*/
- (void)renderer:(id )renderer didRemoveNode:(SCNNode *)node forAnchor:(ARAnchor *
)anchor;
@end



你可能感兴趣的:(ARKit,iOS开发)