ARKit Demo

作者: 倪大头 | 来源:发表于2018-05-15 15:12 被阅读137次

来源:https://www.jianshu.com/p/396a0d1c16f9

创建项目时,选择Augmented Reality App

屏幕快照 2018-05-15 下午3.03.48.png

Content Technology 选项选择 SceneKit

屏幕快照 2018-05-15 下午3.07.17.png

ViewController里有一个自带的飞机模型,替换原有的代码:

#import "ViewController.h"

@interface ViewController () <ARSCNViewDelegate>

@property (nonatomic, strong) IBOutlet ARSCNView *sceneView;

@end

    
@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.sceneView.delegate = self;
    
    // Show statistics such as fps and timing information
    self.sceneView.showsStatistics = YES;
    
    //存放所有3D几何体的容器
    SCNScene *scene = [[SCNScene alloc]init];
    //想要绘制的3D立方体
    SCNBox *boxGeometry = [SCNBox boxWithWidth:0.1 height:0.1 length:0.1 chamferRadius:0.0];
    //将几何体包装为node以便添加到scene
    SCNNode *boxNode = [SCNNode nodeWithGeometry:boxGeometry];
    //把box放在摄像头正前方
    boxNode.position = SCNVector3Make(0, 0, -0.5);
    //rootNode是一个特殊的node,它是所有node的起点
    [scene.rootNode addChildNode:boxNode];
    //将scene赋给view
    self.sceneView.scene = scene;
    //默认光照
    self.sceneView.autoenablesDefaultLighting = YES;
}

- (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];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - ARSCNViewDelegate

/*
// Override to create and configure nodes for anchors added to the view's session.
- (SCNNode *)renderer:(id<SCNSceneRenderer>)renderer nodeForAnchor:(ARAnchor *)anchor {
    SCNNode *node = [SCNNode new];
 
    // Add geometry to the node...
 
    return node;
}
*/

- (void)session:(ARSession *)session didFailWithError:(NSError *)error {
    // Present an error message to the user
    
}

- (void)sessionWasInterrupted:(ARSession *)session {
    // Inform the user that the session has been interrupted, for example, by presenting an overlay
    
}

- (void)sessionInterruptionEnded:(ARSession *)session {
    // Reset tracking and/or remove existing anchors if consistent tracking is required
    
}

@end
WechatIMG15.png

相关文章

  • ARKit Demo

    来源:https://www.jianshu.com/p/396a0d1c16f9 创建项目时,选择Augment...

  • ARKit 学习礼记

    ARKit demo传送门 持续优化更新中... ARKit 简介 增强现实技术(Augmented Realit...

  • ARKit功能demo

    ARKit点击屏幕增加文字 ARKit点击屏幕增加3D模型 ARKit检测到平面自动增加3D模型 QuickLoo...

  • ARKit简单Demo

    ARKit 官网介绍地址官网文档地址 运行版本 1.新建并运行官方自带的demo XCode : File -->...

  • 最火热的AR demo集合

    最火热的AR demo集合https://github.com/olucurious/awesome-arkit

  • iOS ARKit 使用demo

    1.基本概念2.创建项目,模拟下载链接(模型),下载存储到沙盒,展示3.编辑代码, demo下载4.相关编辑软件5...

  • 简单的ARKit demo

    首先创建一个空项目。 一切从最初开始。我是这么想的,当然你也可以选择隔壁的AR 项目开始创建~~~ ViewCon...

  • ARKit Work Shop Demo

    ARKit文章: 到底有多强?苹果的增强现实框架:ARKit ARKit进阶:物理世界 ARKit进阶:材质 De...

  • Animoji demo - #ARKit #Animoji

    iOS 11 && iPhone X采用深感摄像头开发出来的Animoji头像很受欢迎 现在奉上由私有库开发的de...

  • ARKit识别平面-Objective-C

    简单的ARKit的Demo,网上很多,包括Xcode自建的AR项目也可以直接实现一个飞机效果的Demo,不在赘述基...

网友评论

    本文标题:ARKit Demo

    本文链接:https://www.haomeiwen.com/subject/tkzedftx.html