ARAnchor
@interface ARAnchor : NSObject
/**
標識符
*/
@property (nonatomic, readonly) NSUUID *identifier;
/**
錨點的旋轉(zhuǎn)變換矩陣他嚷,定義了錨點的旋轉(zhuǎn)躲撰、位置悔耘、縮放。是一個4x4的矩陣(讀者可以自行科普什么叫4x4矩陣)
*/
@property (nonatomic, readonly) matrix_float4x4 transform;
/**
構(gòu)造方法,一般我們無需構(gòu)造辜王。因為添加一個3D物體時ARKit會有代理告知我們物體的錨點
*/
- (instancetype)initWithTransform:(matrix_float4x4)transform;
@end
ARError
/作用域,一般會表示是哪一個類出現(xiàn)問題
NSString *const ARErrorDomain;
//錯誤碼描述 100:不支持會話追蹤配置,主線由于A9芯片以下的機型會報錯 101:失活狀態(tài) 102:傳感器故障 200:追蹤失敗
typedef NS_ERROR_ENUM(ARErrorDomain, ARErrorCode) {
/** Unsupported session configuration. */
ARErrorCodeUnsupportedConfiguration = 100,
/** A sensor required to run the session is not available. */
ARErrorCodeSensorUnavailable = 101,
/** A sensor failed to provide the required input. */
ARErrorCodeSensorFailed = 102,
/** World tracking has encountered a fatal error. */
ARErrorCodeWorldTrackingFailed = 200,
};
ARFrame
@interface ARFrame : NSObject
/**
時間戳.
*/
@property (nonatomic, readonly) NSTimeInterval timestamp;
/**
緩沖區(qū)圖像幀
*/
@property (nonatomic, readonly) CVPixelBufferRef capturedImage;
/**
相機(表示這個ARFrame是哪一個相機的孕蝉,iPhone7plus有兩個攝像機)
*/
@property (nonatomic, copy, readonly) ARCamera *camera;
/**
返回當前相機捕捉到的錨點數(shù)據(jù)(當一個3D虛擬模型加入到ARKit中時,錨點值得就是這個模型在AR中的位置)
*/
@property (nonatomic, copy, readonly) NSArray *anchors;
/**
燈光腌逢,詳情可見本章節(jié)ARLightEstimate類介紹(指的是燈光強度 一般是0-2000降淮,系統(tǒng)默認1000)
*/
@property (nonatomic, copy, nullable, readonly) ARLightEstimate *lightEstimate;
/**
特征點(應(yīng)該是捕捉平地或者人臉的,比較蘋果有自帶的人臉識別功能)
*/
@property (nonatomic, nullable, readonly) ARPointCloud *rawFeaturePoints;
/**
根據(jù)2D坐標點搜索3D模型搏讶,這個方法通常用于佳鳖,當我們在手機屏幕點擊某一個點的時候,可以捕捉到這一個點所在的3D模型的位置媒惕,至于為什么是一個數(shù)組非常好理解系吩。手機屏幕一個是長方形,這是一個二維空間妒蔚。而相機捕捉到的是一個由這個二維空間射出去的長方體穿挨,我們點擊屏幕一個點可以理解為在這個長方體的邊緣射出一條線,這一條線上可能會有多個3D物體模型
point:2D坐標點(手機屏幕某一點)
ARHitTestResultType:捕捉類型 點還是面
(NSArray *):追蹤結(jié)果數(shù)組 詳情見本章節(jié)ARHitTestResult類介紹
*/
- (NSArray *)hitTest:(CGPoint)point types:(ARHitTestResultType)types;
/**
相機窗口的的坐標變換(可用于相機橫豎屏的旋轉(zhuǎn)適配)
*/
- (CGAffineTransform)displayTransformWithViewportSize:(CGSize)viewportSize orientation:(UIInterfaceOrientation)orientation;
@end
ARHitTestResult
//捕捉類型枚舉
typedef NS_OPTIONS(NSUInteger, ARHitTestResultType) {
/**點. */
ARHitTestResultTypeFeaturePoint = (1 << 0),
/**水平面 y為0. */
ARHitTestResultTypeEstimatedHorizontalPlane = (1 << 1),
/**已結(jié)存在的平面. */
ARHitTestResultTypeExistingPlane = (1 << 3),
/**已結(jié)存在的錨點和平面. */
ARHitTestResultTypeExistingPlaneUsingExtent = (1 << 4),
} NS_SWIFT_NAME(ARHitTestResult.ResultType);
/**
捕捉類型
*/
@property (nonatomic, readonly) ARHitTestResultType type;
/**
3D虛擬物體與相機的距離(單位:米)
*/
@property (nonatomic, readonly) CGFloat distance;
/**
本地坐標矩陣(世界坐標指的是相機為場景原點的坐標肴盏,而每一個3D物體自身有一個場景科盛,本地坐標就是相對于這個場景的坐標)類似于frame和bounds的區(qū)別
*/
@property (nonatomic, readonly) matrix_float4x4 localTransform;
/**
世界坐標矩陣
*/
@property (nonatomic, readonly) matrix_float4x4 worldTransform;
/**
錨點(3D虛擬物體,在虛擬世界有一個位置菜皂,這個位置參數(shù)是SceneKit中的SCNVector3:三維矢量)土涝,而錨點anchor是這個物體在AR現(xiàn)實場景中的位置,是一個4x4的矩陣
*/
@property (nonatomic, strong, nullable, readonly) ARAnchor *anchor;
@end
@interface ARLightEstimate : NSObject
/**
燈光強度 范圍0-2000 默認1000
*/
@property (nonatomic, readonly) CGFloat ambientIntensity;
@end
/**
平地類型幌墓,目前只有一個但壮,就是水平面
*/
@property (nonatomic, readonly) ARPlaneAnchorAlignment alignment;
/**
3軸矢量結(jié)構(gòu)體,表示平地的中心點 x/y/z
*/
@property (nonatomic, readonly) vector_float3 center;
/**
3軸矢量結(jié)構(gòu)體常侣,表示平地的大欣(寬度和高度) x/y/z
*/
@property (nonatomic, readonly) vector_float3 extent;
@end
@interface ARPointCloud : NSObject
/**
點的數(shù)量
*/
@property (nonatomic, readonly) NSUInteger count;
/**
每一個點的位置的集合(結(jié)構(gòu)體帶*表示的是結(jié)構(gòu)體數(shù)組)
*/
@property (nonatomic, readonly) const vector_float3 *points;
@end
//會話追蹤配置類
@interface ARSessionConfiguration : NSObject
/**
當前設(shè)備是否支持,一般A9芯片以下設(shè)備不支持
*/
@property(class, nonatomic, readonly) BOOL isSupported;
/**
會話的對其方式胳施,這里的對其指的是3D世界的坐標溯祸。枚舉值見下方
*/
@property (nonatomic, readwrite) ARWorldAlignment worldAlignment;
/**
是否需要自適應(yīng)燈光效果,默認是YES
*/
@property (nonatomic, readwrite, getter=isLightEstimationEnabled) BOOL lightEstimationEnabled;
@end
//世界會話追蹤配置,蘋果建議我們使用這個類焦辅,這個子類只有一個屬性博杖,也就是可以幫助我們追蹤相機捕捉到的平地
@interface ARWorldTrackingSessionConfiguration : ARSessionConfiguration
/**
偵查類型。枚舉值見下方(默認偵查平地)
*/
@property (nonatomic, readwrite) ARPlaneDetection planeDetection;
@end
ARSCNView
@interface ARSCNView : SCNView
/**
代理
*/
@property (nonatomic, weak, nullable) id delegate;
/**
AR會話
*/
@property (nonatomic, strong) ARSession *session;
/**
場景
*/
@property(nonatomic, strong) SCNScene *scene;
/**
是否自動適應(yīng)燈光
*/
@property(nonatomic) BOOL automaticallyUpdatesLighting;
/**
返回對應(yīng)節(jié)點的錨點筷登,節(jié)點是一個3D虛擬物體剃根,它的坐標是虛擬場景中的坐標,而錨點ARAnchor是ARKit中現(xiàn)實世界的坐標前方。
*/
- (nullable ARAnchor *)anchorForNode:(SCNNode *)node;
/**
返回對應(yīng)錨點的物體
*/
- (nullable SCNNode *)nodeForAnchor:(ARAnchor *)anchor;
/**
根據(jù)2D坐標點搜索3D模型狈醉,這個方法通常用于,當我們在手機屏幕點擊某一個點的時候惠险,可以捕捉到這一個點所在的3D模型的位置苗傅,至于為什么是一個數(shù)組非常好理解。手機屏幕一個是長方形班巩,這是一個二維空間渣慕。而相機捕捉到的是一個由這個二維空間射出去的長方體,我們點擊屏幕一個點可以理解為在這個長方體的邊緣射出一條線抱慌,這一條線上可能會有多個3D物體模型
point:2D坐標點(手機屏幕某一點)
ARHitTestResultType:捕捉類型 點還是面
(NSArray *):追蹤結(jié)果數(shù)組 詳情見本章節(jié)ARHitTestResult類介紹
數(shù)組的結(jié)果排序是由近到遠
*/
- (NSArray *)hitTest:(CGPoint)point types:(ARHitTestResultType)types;
@end
ARSCNViewDelegate
//代理
#pragma mark - ARSCNViewDelegate
//代理的內(nèi)部實現(xiàn)了SCNSceneRendererDelegate:scenekit代理 和ARSessionObserver:ARSession監(jiān)聽(KVO機制)
@protocol ARSCNViewDelegate
@optional
/**
自定義節(jié)點的錨點
*/
- (nullable SCNNode *)renderer:(id )renderer nodeForAnchor:(ARAnchor *)anchor;
/**
當添加節(jié)點是會調(diào)用摇庙,我們可以通過這個代理方法得知我們添加一個虛擬物體到AR場景下的錨點(AR現(xiàn)實世界中的坐標)
*/
- (void)renderer:(id )renderer didAddNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor;
/**
將要刷新節(jié)點
*/
- (void)renderer:(id )renderer willUpdateNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor;
/**
已經(jīng)刷新節(jié)點
*/
- (void)renderer:(id )renderer didUpdateNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor;
/**
移除節(jié)點
*/
- (void)renderer:(id )renderer didRemoveNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor;
@end
ARSession
@interface ARSession : NSObject
/**
代理
*/
@property (nonatomic, weak) id delegate;
/**
指定代理執(zhí)行的線程(主線程不會有延遲,子線程會有延遲)遥缕,不指定的話默認主線程
*/
@property (nonatomic, strong, nullable) dispatch_queue_t delegateQueue;
/**
相機當前的位置(是由會話追蹤配置計算出來的)
*/
@property (nonatomic, copy, nullable, readonly) ARFrame *currentFrame;
/**
會話追蹤配置
*/
@property (nonatomic, copy, nullable, readonly) ARSessionConfiguration *configuration;
/**
運行會話(這行代碼就是開啟AR的關(guān)鍵所在)
*/
- (void)runWithConfiguration:(ARSessionConfiguration *)configuration NS_SWIFT_UNAVAILABLE("Use run(_:options:)");
/**
運行會話卫袒,只是多了一個參數(shù)ARSessionRunOptions:作用就是會話斷開重連時的行為。ARSessionRunOptionResetTracking:表示充值追蹤 ARSessionRunOptionRemoveExistingAnchors:移除現(xiàn)有錨點
*/
- (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;
/**
相機改變追蹤狀態(tài)
*/
- (void)session:(ARSession *)session cameraDidChangeTrackingState:(ARCamera *)camera;
/**
session意外斷開(如果開啟ARSession之后夕凝,APP退到后臺就有可能導(dǎo)致會話斷開)
*/
- (void)sessionWasInterrupted:(ARSession *)session;
/**
session會話斷開恢復(fù)(短時間退到后臺再進入APP會自動恢復(fù))
*/
- (void)sessionInterruptionEnded:(ARSession *)session;
@end
#pragma mark - ARSessionDelegate
@protocol ARSessionDelegate
@optional
/**
更新相機位置
*/
- (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
ARCamera
@interface ARCamera : NSObject
/**
4x4矩陣表示相機位置,同ARAnchor
*/
@property (nonatomic, readonly) matrix_float4x4 transform;
/**
相機方向(旋轉(zhuǎn))的矢量歐拉角
分別是x/y/z
*/
@property (nonatomic, readonly) vector_float3 eulerAngles;
/**
相機追蹤狀態(tài)(在下方會有枚舉值介紹)
*/
@property (nonatomic, readonly) ARTrackingState trackingState NS_REFINED_FOR_SWIFT;
/**
追蹤運動類型
*/
@property (nonatomic, readonly) ARTrackingStateReason trackingStateReason NS_REFINED_FOR_SWIFT;
/**
相機曲率(筆者有點費解户秤,反復(fù)揣摩應(yīng)該是與焦距相關(guān)參數(shù))
3x3矩陣
fx 0 px
0 fy py
0 0 1
*/
@property (nonatomic, readonly) matrix_float3x3 intrinsics;
/**
攝像頭分辨率
*/
@property (nonatomic, readonly) CGSize imageResolution;
/**
投影矩陣
*/
@property (nonatomic, readonly) matrix_float4x4 projectionMatrix;
/**
創(chuàng)建相機投影矩陣
*/
- (matrix_float4x4)projectionMatrixWithViewportSize:(CGSize)viewportSize orientation:(UIInterfaceOrientation)orientation zNear:(CGFloat)zNear zFar:(CGFloat)zFar;
@end
//相機追蹤狀態(tài)枚舉
typedef NS_ENUM(NSInteger, ARTrackingState) {
/**不被允許 */
ARTrackingStateNotAvailable,
/**最小 */
ARTrackingStateLimited,
/**正常. */
ARTrackingStateNormal,
} NS_REFINED_FOR_SWIFT;
/**
追蹤運動類型
*/
API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(macos, watchos, tvos)
typedef NS_ENUM(NSInteger, ARTrackingStateReason) {
/**無. */
ARTrackingStateReasonNone,
/**運動. */
ARTrackingStateReasonExcessiveMotion,
/**臉部捕捉. */
ARTrackingStateReasonInsufficientFeatures,
} NS_REFINED_FOR_SWIFT;
ARKit API
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門姓赤,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人仲吏,你說我怎么就攤上這事不铆◎蚍伲” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵誓斥,是天一觀的道長只洒。 經(jīng)常有香客問我,道長劳坑,這世上最難降的妖魔是什么毕谴? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮泡垃,結(jié)果婚禮上析珊,老公的妹妹穿的比我還像新娘羡鸥。我一直安慰自己蔑穴,他們只是感情好,可當我...
- 文/花漫 我一把揭開白布惧浴。 她就那樣靜靜地躺著存和,像睡著了一般。 火紅的嫁衣襯著肌膚如雪衷旅。 梳的紋絲不亂的頭發(fā)上捐腿,一...
- 文/蒼蘭香墨 我猛地睜開眼家乘,長吁一口氣:“原來是場噩夢啊……” “哼蝗羊!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起仁锯,我...
- 正文 年R本政府宣布咽笼,位于F島的核電站,受9級特大地震影響戚炫,放射性物質(zhì)發(fā)生泄漏剑刑。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一双肤、第九天 我趴在偏房一處隱蔽的房頂上張望施掏。 院中可真熱鬧,春花似錦茅糜、人聲如沸七芭。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽狸驳。三九已至,卻和暖如春缩赛,著一層夾襖步出監(jiān)牢的瞬間耙箍,已是汗流浹背。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 轉(zhuǎn)載請注明出處:http://www.reibang.com/p/3c7ee58d40f4 1.1-ARKit框架...
- 一扇丛、AR簡介: 多媒體捕捉現(xiàn)實圖像:如攝像頭 三維建模:3D立體模型 傳感器追蹤:主要追蹤現(xiàn)實世界動態(tài)物體的六軸變...