ARKit1.5里,新增了检测竖直平面的功能。为此特意写一个demo。
下面是效果图:
和之前的水平平面相比 其实就是把多一个属性赋值给世界追踪类
其他代码基本一样
代码
#import "ViewController.h"
@interface ViewController () <ARSCNViewDelegate>
@property (nonatomic, strong) IBOutlet ARSCNView *sceneView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 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 new];
// 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];
configuration.detectionImages = [ARReferenceImage referenceImagesInGroupNamed:@"AR Resources" bundle:nil];
[self.sceneView.session runWithConfiguration:configuration options:ARSessionRunOptionResetTracking |ARSessionRunOptionRemoveExistingAnchors];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.sceneView.session pause];
}
- (void)renderer:(id<SCNSceneRenderer>)renderer didAddNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor {
ARImageAnchor * imageAnchor = (ARImageAnchor *)anchor;
//获取参考图片对象
ARReferenceImage * referenceImage = imageAnchor.referenceImage;
if ([referenceImage.name isEqual: @"lcw"]) {
SCNNode * tempNode = [SCNNode new];
CGFloat w = referenceImage.physicalSize.width;
CGFloat h = referenceImage.physicalSize.height;
SCNBox * box = [SCNBox boxWithWidth:w height:h length:0.01 chamferRadius:0];
tempNode.geometry = box;
tempNode.eulerAngles = SCNVector3Make(-M_PI/2.0, 0, 0);
tempNode.opacity = 0.5;//透明度
[node addChildNode:tempNode];
}
}
@end
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。