首先创建一个空项目。
02981D42-3111-4749-96E2-22B123EEE1F4.png一切从最初开始。我是这么想的,当然你也可以选择隔壁的AR 项目开始创建~~~
ViewController.m 里面开始堆代码:(没错,就是OC语音,有机会就考虑一下swift吧~~~)
#import "ViewController.h"
#import <SceneKit/SceneKit.h>
#import <ARKit/ARKit.h>
#import "Masonry.h"
@interface ViewController ()<ARSCNViewDelegate>
@property (nonatomic, strong) ARSCNView *sceneView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
ARSCNView *sceneView = [ARSCNView new];
[self.view addSubview:sceneView];
[sceneView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(0);
}];
self.sceneView = sceneView;
// Set the view's delegate
self.sceneView.delegate = self;
// Show statistics such as fps and timing information
self.sceneView.showsStatistics = YES;
// Create a new scene
SCNScene *scene = [SCNScene sceneNamed:@"ship.scn"];
// Set the scene to the view
self.sceneView.scene = scene;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Create a session configuration
ARWorldTrackingConfiguration *configuration = [ARWorldTrackingConfiguration new];
// Run the view's session
[self.sceneView.session runWithConfiguration:configuration];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// Pause the view's session
[self.sceneView.session pause];
}
@end
然后就可以跑项目了,
然后你大概会遇见奔溃的现象,
这个是很常见的问题。
因为项目要调用摄像头,然而你居然没有在 Info.plist 里面写上相关的内容:
<key>NSCameraUsageDescription</key>
<string>This application will use the camera for Augmented Reality.</string>
所以奔溃也别见怪啊~~~~
至于素材问题啊。。。
最简单,你创建一个AR项目,然后从那里拉素材出来用就是啊~~~
多简单啊~~~
ARSCNViewDelegate 协议还是没有用上,
这个是当然的,毕竟这个只是一个简单的demo,在不用AR项目创建的情况下,自行创建AR的项目而已~~~
所以不用在意。
木子才。
网友评论