Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // Shoji
- //
- // Created by MizushimaYusuke on 2018/01/12.
- // 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 + 0.03, hit.worldTransform.columns.3.z)
- let paper = SCNBox(width: 0.03, height: 0.06, length: 0.001, chamferRadius: 0)
- let paperNode = SCNNode(geometry: paper)
- paperNode.position = position
- sceneView.scene.rootNode.addChildNode(paperNode)
- stride(from: -0.015, through: 0.015, by: 0.005).forEach { x in
- let barv = SCNBox(width: 0.001, height: 0.06, length: 0.0015, chamferRadius: 0)
- barv.firstMaterial?.diffuse.contents = UIColor.brown
- let barvNode = SCNNode(geometry: barv)
- barvNode.position = SCNVector3(x, 0, 0)
- paperNode.addChildNode(barvNode)
- }
- stride(from: -0.03, through: 0.03, by: 0.005).forEach { y in
- let barh = SCNBox(width: 0.03, height: 0.001, length: 0.0015, chamferRadius: 0)
- barh.firstMaterial?.diffuse.contents = UIColor.brown
- let barhNode = SCNNode(geometry: barh)
- barhNode.position = SCNVector3(0, y, 0)
- paperNode.addChildNode(barhNode)
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment