|
| 1 | +// |
| 2 | +// ViewController.swift |
| 3 | +// YoriJori |
| 4 | +// |
| 5 | +// Created by 김강현 on 7/6/24. |
| 6 | +// |
| 7 | + |
| 8 | +import UIKit |
| 9 | +import SceneKit |
| 10 | +import ARKit |
| 11 | + |
| 12 | +class ViewController: UIViewController, ARSCNViewDelegate { |
| 13 | + |
| 14 | + @IBOutlet var sceneView: ARSCNView! |
| 15 | + |
| 16 | + override func viewDidLoad() { |
| 17 | + super.viewDidLoad() |
| 18 | + |
| 19 | + // Set the view's delegate |
| 20 | + sceneView.delegate = self |
| 21 | + |
| 22 | + // Show statistics such as fps and timing information |
| 23 | + sceneView.showsStatistics = true |
| 24 | + |
| 25 | + // Create a new scene |
| 26 | + let scene = SCNScene(named: "art.scnassets/ship.scn")! |
| 27 | + |
| 28 | + // Set the scene to the view |
| 29 | + sceneView.scene = scene |
| 30 | + } |
| 31 | + |
| 32 | + override func viewWillAppear(_ animated: Bool) { |
| 33 | + super.viewWillAppear(animated) |
| 34 | + |
| 35 | + // Create a session configuration |
| 36 | + let configuration = ARWorldTrackingConfiguration() |
| 37 | + |
| 38 | + // Run the view's session |
| 39 | + sceneView.session.run(configuration) |
| 40 | + } |
| 41 | + |
| 42 | + override func viewWillDisappear(_ animated: Bool) { |
| 43 | + super.viewWillDisappear(animated) |
| 44 | + |
| 45 | + // Pause the view's session |
| 46 | + sceneView.session.pause() |
| 47 | + } |
| 48 | + |
| 49 | + // MARK: - ARSCNViewDelegate |
| 50 | + |
| 51 | +/* |
| 52 | + // Override to create and configure nodes for anchors added to the view's session. |
| 53 | + func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? { |
| 54 | + let node = SCNNode() |
| 55 | + |
| 56 | + return node |
| 57 | + } |
| 58 | +*/ |
| 59 | + |
| 60 | + func session(_ session: ARSession, didFailWithError error: Error) { |
| 61 | + // Present an error message to the user |
| 62 | + |
| 63 | + } |
| 64 | + |
| 65 | + func sessionWasInterrupted(_ session: ARSession) { |
| 66 | + // Inform the user that the session has been interrupted, for example, by presenting an overlay |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | + func sessionInterruptionEnded(_ session: ARSession) { |
| 71 | + // Reset tracking and/or remove existing anchors if consistent tracking is required |
| 72 | + |
| 73 | + } |
| 74 | +} |
0 commit comments