Created
October 1, 2017 04:09
-
-
Save iannase/8b0eb141eb5888fba0cd5c7b8ef40192 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// ARDicee | |
// | |
// Created by Ian on 9/30/17. | |
// Copyright © 2017 IanAnnase. 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 | |
// let sphere = SCNSphere(radius:0.2) | |
// | |
// let material = SCNMaterial() | |
// | |
// material.diffuse.contents = UIImage(named: "art.scnassets/neptune.jpg") | |
// | |
// sphere.materials = [material] | |
// | |
// let node = SCNNode() | |
// | |
// node.position = SCNVector3(x: 0, y: 0.1, z: -1) | |
// | |
// node.geometry = sphere | |
// | |
// sceneView.scene.rootNode.addChildNode(node) | |
sceneView.autoenablesDefaultLighting = true | |
// Create a new scene | |
let diceScene = SCNScene(named: "art.scnassets/diceCollada.scn")! | |
if let diceNode = diceScene.rootNode.childNode(withName: "Dice", recursively: true) { | |
diceNode.position = SCNVector3(x: 0, y:0, z:-0.1) | |
sceneView.scene.rootNode.addChildNode(diceNode) | |
} | |
} | |
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() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment