Simplest Video Add to SceneKit - Lesson 1
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