ar的检测方法是ARSCNView的代理的方法
主要代码如下:
_jpARSCNView.delegate = self;
<ARSCNViewDelegate>
-(void)renderer:(id<SCNSceneRenderer>)renderer didAddNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor ;
-(void)renderer:(id<SCNSceneRenderer>)renderer didUpdateNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor ;
-(void)renderer:(id<SCNSceneRenderer>)renderer didRemoveNode:(SCNNode *)node forAnchor:(ARAnchor *)anchor ;
构建几何体的主要代码如下:
######利用SCNBox来创建
SCNScene * jpScene = [[SCNScene alloc]init];
SCNBox * jpBox = [SCNBox boxWithWidth:0.1 height:0.1 length:0.1 chamferRadius:0];
SCNNode * jpNode = [SCNNode nodeWithGeometry:jpBox];
jpNode.position = SCNVector3Make(0, 0, -0.5);
[jpScene.rootNode addChildNode:jpNode];
self.jpARSCNView.scene = jpScene;
######利用UIImage 和 SCNMaterial 来创建
self.anchor = anchor;
//extent 范围
CGFloat w = anchor.extent.x;
CGFloat h = anchor.extent.z;
_planeGeometry = [SCNPlane planeWithWidth:w height:h];
SCNMaterial * material = [[SCNMaterial alloc]init];
UIImage * image = [UIImage imageNamed:@"fabric"];
//扩散 - diffuse
material.diffuse.contents = image;
material.lightingModelName = SCNLightingModelPhysicallyBased;
_planeGeometry.materials = @[material];
SCNNode * planeNode = [SCNNode nodeWithGeometry:_planeGeometry];
planeNode.position = SCNVector3Make(anchor.center.x, 0, anchor.center.z);
// SceneKit 里的平面默认是垂直的,所以需要旋转90度来匹配 ARKit 中的平面
CGFloat x = -M_PI/2.0;
planeNode.transform = SCNMatrix4MakeRotation(x, 1.0, 0.0, 0.0);
[self setTextureScale];
[self addChildNode:planeNode];
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。