Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // Star
- //
- // Created by MizushimaYusuke on 2018/03/15.
- // Copyright © 2018 MizushimaYusuke. All rights reserved.
- //
- import UIKit
- import SceneKit
- import ARKit
- 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
- sceneView.autoenablesDefaultLighting = true
- // Create a new scene
- let scene = SCNScene()
- // Set the scene to the view
- sceneView.scene = scene
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- // Create a session configuration
- let configuration = ARWorldTrackingConfiguration()
- // Run the view's session
- sceneView.session.run(configuration)
- }
- override func viewWillDisappear(_ animated: Bool) {
- super.viewWillDisappear(animated)
- // Pause the view's session
- sceneView.session.pause()
- }
- override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
- if let p = touches.first?.location(in: sceneView) {
- if let hit = sceneView.hitTest(p, types: .featurePoint).first {
- let position = SCNVector3(hit.worldTransform.columns.3.x, hit.worldTransform.columns.3.y, hit.worldTransform.columns.3.z)
- let node = SCNNode()
- node.position = position
- sceneView.scene.rootNode.addChildNode(node)
- let star = SCNText(string: "★", extrusionDepth: 10)
- star.font = UIFont.systemFont(ofSize: 100)
- star.firstMaterial?.diffuse.contents = UIColor.yellow
- let starNode = SCNNode(geometry: star)
- starNode.scale = SCNVector3(0.0003, 0.0003, 0.0003)
- node.addChildNode(starNode)
- node.runAction(SCNAction.rotateBy(x: 0, y: .pi * 2.0, z: 0, duration: 3.0))
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment