티스토리 뷰

반응형

SCNGeometry를 상속받은 친구들 중, SCNText, SCNBox, SCNSphere 를 화면에 띄워보자 : )

 



일단 프로젝트를 만들면 scene에 기본으로 넣어져있는 ship.scn을 지우고 scene에 아무 것도 없게 해준다 

let scene = SCNScene(named: "art.scnassets/ship.scn")!

 

즉 이렇게 시작한다 

class ViewController: UIViewController, ARSCNViewDelegate {

    @IBOutlet var sceneView: ARSCNView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Set the view's delegate
        sceneView.delegate = self
        
        // Show statistics such as fps and timing information
        sceneView.showsStatistics = true
        
        // Create a new scene
        let scene = SCNScene()
        
        // Set the scene to the view
        sceneView.scene = scene
     }
 }

 

[ 1 ] SCNText 

 

먼저 Text를 띄워보자 

 

1. SCNText를 구성해주기 

 

Hello AR이란 Text를 만든다 

Text의 color는 blue로 해준다 

let text = SCNText(string: "Hello AR", extrusionDepth: 1.0)
text.firstMaterial?.diffuse.contents = UIColor.blue

2. SCNNode 에 geometry 객체를 실어주기 

node의 position이랑 scale도 설정해준다 

let textNode = SCNNode(geometry: text)
textNode.scale = SCNVector3(0.02, 0.02, 0.02)
textNode.position = SCNVector3(0, 0, -1)

ARKit에서 모든 단위는 미터 단위이다.

(0.02는 0.02m = 2cm를 나타낸다.)

scale을 down시키지 않으면 너무 글씨가 커서 0.02 다운 스케일 해준다
(The default scale is 1.0 in all three dimensions..!  기본 스케일은 1,1,1 이다 ) 

postion도 나에게서(디바이스에서)  textNode를 조금 뒤로 해주기 위해 z 포지션을 -1로 설정해준다

출처: 군옥수수님의 블로그 (https://ehdrjsdlzzzz.github.io/2018/10/13/ARKit-Reference-1/)

 

3. scene의 rootNode에 2에서 만든 노드를 붙이기 

sceneView.scene.rootNode.addChildNode(textNode)

 

그 상태에서 디바이스에 돌려보면, 이렇게 나온다

SCNVector3(0, 0, -1) 으로 텍스트 노드의 포지션을 설정해주었는데,

텍스트의 시작점을 x축 0, y축 0 (즉 디바이스의 중간)에 둔 것 같다 

 

디바이스를 옆으로 돌려보면 Hello AR 텍스트가 잘 위치했음을 볼 수 있다  

반응형
댓글