ARKit必须XCode 9.0 + iOS 11真机,A9芯片的设备(SE,6S,6S-P,7,7-P,X,8,8-P)才能玩
创建工程:
next:
Content Technology:选择SceneKit
首先我们先看一张图:
CNScene 他都有一个RootNode;万物皆scene
工程创建成功后会自动生成一些代码:
sceneView.showsStatistics = true
为true会显示最下面状态栏
ARKit入门需掌握4大要素:
创建了一个场景
let scene = SCNScene()
1.几何
//创建一个圆
let sphere = SCNSphere(radius: 0.1)
2.节点
let sphereNode = SCNNode(geometry: sphere)
sphereNode.position = SCNVector3(0,0,-0.5)
scene.rootNode.addChildNode(sphereNode)
3.渲染
let material = SCNMaterial() // material 渲染器
material.diffuse.contents = UIImage(named: "earth.jpg")
sphere.materials = [material]
4.手势
func registerGestureRecognizers(){
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(tapped))
sceneView.scene = scene //把创建的场景添加到sceneView.scene上
self.sceneView.addGestureRecognizer(tapGestureRecognizer)
}
@objc func tapped (recognizer: UIGestureRecognizer){
}
OK!真机跑一下看看效果,你会被惊住的!!!