Guest User

Untitled

a guest
Mar 24th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. //
  2. // ViewController.swift
  3. // Star
  4. //
  5. // Created by MizushimaYusuke on 2018/03/15.
  6. // Copyright © 2018 MizushimaYusuke. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import SceneKit
  11. import ARKit
  12.  
  13. class ViewController: UIViewController, ARSCNViewDelegate {
  14.  
  15. @IBOutlet var sceneView: ARSCNView!
  16.  
  17. override func viewDidLoad() {
  18. super.viewDidLoad()
  19.  
  20. // Set the view's delegate
  21. sceneView.delegate = self
  22.  
  23. // Show statistics such as fps and timing information
  24. sceneView.showsStatistics = true
  25. sceneView.autoenablesDefaultLighting = true
  26.  
  27. // Create a new scene
  28. let scene = SCNScene()
  29.  
  30. // Set the scene to the view
  31. sceneView.scene = scene
  32. }
  33.  
  34. override func viewWillAppear(_ animated: Bool) {
  35. super.viewWillAppear(animated)
  36.  
  37. // Create a session configuration
  38. let configuration = ARWorldTrackingConfiguration()
  39.  
  40. // Run the view's session
  41. sceneView.session.run(configuration)
  42. }
  43.  
  44. override func viewWillDisappear(_ animated: Bool) {
  45. super.viewWillDisappear(animated)
  46.  
  47. // Pause the view's session
  48. sceneView.session.pause()
  49. }
  50.  
  51. override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  52. if let p = touches.first?.location(in: sceneView) {
  53. if let hit = sceneView.hitTest(p, types: .featurePoint).first {
  54.  
  55. let position = SCNVector3(hit.worldTransform.columns.3.x, hit.worldTransform.columns.3.y, hit.worldTransform.columns.3.z)
  56.  
  57. let node = SCNNode()
  58. node.position = position
  59. sceneView.scene.rootNode.addChildNode(node)
  60.  
  61. let star = SCNText(string: "★", extrusionDepth: 10)
  62. star.font = UIFont.systemFont(ofSize: 100)
  63. star.firstMaterial?.diffuse.contents = UIColor.yellow
  64.  
  65. let starNode = SCNNode(geometry: star)
  66. starNode.scale = SCNVector3(0.0003, 0.0003, 0.0003)
  67. node.addChildNode(starNode)
  68.  
  69. node.runAction(SCNAction.rotateBy(x: 0, y: .pi * 2.0, z: 0, duration: 3.0))
  70. }
  71. }
  72. }
  73.  
  74. }
Add Comment
Please, Sign In to add comment