Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // dot3D
- //
- // Created by MizushimaYusuke on 2017/12/11.
- // 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
- // 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()
- }
- var ready = 0
- var points:[SCNVector3] = []
- override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
- if let p = touches.first?.location(in: sceneView) {
- if let hit = sceneView.hitTest(p, options: [.sortResults : true]).first?.node {
- if hit.geometry is SCNSphere {
- hit.geometry?.firstMaterial?.diffuse.contents = UIColor.yellow
- }
- }
- if ready == 0 {
- ready += 1
- if let hit = sceneView.hitTest(p, types: .featurePoint).first {
- let position = SCNVector3(hit.worldTransform.columns.3.x, hit.worldTransform.columns.3.y + 0.05, hit.worldTransform.columns.3.z - 0.02)
- stride(from: 0, to: 0.06, by: 0.02).forEach { x in
- stride(from: 0, to: 0.06, by: 0.02).forEach { y in
- stride(from: 0, to: 0.06, by: 0.02).forEach { z in
- let dot = SCNSphere(radius: 0.005)
- dot.firstMaterial?.diffuse.contents = UIColor.black
- let dotNode = SCNNode(geometry: dot)
- dotNode.position = SCNVector3(position.x + Float(x), position.y + Float(y), position.z + Float(z))
- sceneView.scene.rootNode.addChildNode(dotNode)
- }
- }
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment