Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // flipThrough
- //
- // Created by MizushimaYusuke on 2017/12/14.
- // Copyright © 2017 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)
- self.createPage(position, 50)
- }
- }
- }
- func createPage(_ position: SCNVector3, _ cnt: Int) {
- if cnt < 0 {
- return
- }
- let page = SCNBox(width: 0.02, height: 0.001, length: 0.02, chamferRadius: 0.0)
- page.firstMaterial?.diffuse.contents = UIColor(hue: 0.13, saturation: 0.1, brightness: 0.8, alpha: 1)
- let pageNode = SCNNode(geometry: page)
- pageNode.pivot = SCNMatrix4MakeTranslation(0.01, 0, 0)
- pageNode.position = position
- sceneView.scene.rootNode.addChildNode(pageNode)
- pageNode.runAction(.rotateBy(x: 0, y: 0, z: -.pi, duration: 0.3))
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
- self.createPage(position, cnt - 1)
- }
- }
- }
Add Comment
Please, Sign In to add comment