info.plist 에서 카메라 설정이 필요함!
class ViewController: UIViewController {
// MARK: - Properties
let myButton = UIButton() // addButton
let sceneView = ARSCNView() // ARSceneView
let configuration = ARWorldTrackingConfiguration() // Configure
// MARK: - LifeCycle
override func viewDidLoad() {
super.viewDidLoad()
buildViews()
// 디버그 시 사용되는 옵션
sceneView.debugOptions = [
ARSCNDebugOptions.showFeaturePoints,
ARSCNDebugOptions.showWorldOrigin
]
sceneView.session.run(configuration) // arSceneView를 실행해서 카메라 연결
}
// 버튼 클릭 이벤트
@objc
func addNodes() {
let node = SCNNode() // 노드(가상의 물체) 생성
node.geometry = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0.9) // node의 크기, 모양 설정 // 박스(곡률을 0 으로 하면 정육면체가 생성된다.)
node.geometry?.firstMaterial?.diffuse.contents = UIColor.yellow // node 의 색상
node.position = SCNVector3(0,0,0) // node가 XYZ축 의 교점을 기준으로 위치할 곳 설정
sceneView.scene.rootNode.addChildNode(node) // ARSceneView 위에 올려 놓음
}
// AR의 위치는 전체, 버튼의 위치는 적당히 알아서 잡는다.
}