Created
September 18, 2020 16:07
-
-
Save jungchris/2975ae277741253d43e25578a638fd9a to your computer and use it in GitHub Desktop.
Simplest Video Add to SceneKit - Lesson 1
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
import UIKit | |
import SceneKit | |
import ARKit | |
class ViewController: UIViewController, ARSCNViewDelegate { | |
@IBOutlet var sceneView: ARSCNView! | |
var player : AVPlayer? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
sceneView.delegate = self | |
} | |
override func viewDidAppear(_ animated: Bool) { | |
super.viewDidAppear(animated) | |
addARVideo() | |
} | |
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
let configuration = ARWorldTrackingConfiguration() | |
sceneView.session.run(configuration) | |
} | |
override func viewWillDisappear(_ animated: Bool) { | |
super.viewWillDisappear(animated) | |
sceneView.session.pause() | |
} | |
func addARVideo() { | |
let fileURL = URL(fileURLWithPath: Bundle.main.path(forResource: "training", ofType: "mp4")!) | |
player = AVPlayer(url: fileURL) | |
let playerGEO = SCNPlane(width: 1.6, height: 0.9) | |
playerGEO.firstMaterial?.diffuse.contents = player | |
playerGEO.firstMaterial?.isDoubleSided = true | |
let playerNode = SCNNode(geometry: playerGEO) | |
playerNode.position.z = -2.0 | |
sceneView.scene.rootNode.addChildNode(playerNode) | |
player!.play() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment