Hi there,
I am pretty new to all of this so be nice :-)
I am using ARKit and Xcode10.
So far I ahve managed to track one image with one 'video' file playing ontop of it and tracking that.
What I want to beable to do is have multiple versions of this. Let me elaborate. The App I am looking to build is to go along with our Theatre Show Program, As the person hovers over a certain image on a certain page I want it to play a different video that is related to that picture.
My current code looks like this : Any help will be greatly greatly appriciated
import UIKit
import SceneKit
import ARKit
import AVFoundation
import SpriteKit
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(named: "art.scnassets/program.scn")!
// Set the scene to the view
sceneView.scene = scene
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Create a session configuration
let configuration = ARImageTrackingConfiguration()
guard let arImages = ARReferenceImage.referenceImages(inGroupNamed: "AR Resources", bundle: nil) else { return }
configuration.trackingImages = arImages
// 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()
}
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
guard anchor is ARImageAnchor else { return }
//Containter
guard let container = sceneView.scene.rootNode.childNode(withName: "container", recursively: false) else { return }
container.removeFromParentNode()
node.addChildNode(container)
container.isHidden = false
//Video
let videoURL = Bundle.main.url(forResource: "FrancoOpening", withExtension: "mp4")!
let videoPlayer = AVPlayer(url: videoURL)
let videoScene = SKScene(size: CGSize(width: 720.0, height: 1280.0))
let videoNode = SKVideoNode(avPlayer: videoPlayer)
videoNode.position = CGPoint(x: videoScene.size.width / 2, y: videoScene.size.height / 2)
videoNode.size = videoScene.size
videoNode.yScale = -1
videoNode.play()
videoScene.addChild(videoNode)
guard let video = container.childNode(withName: "video", recursively: true) else { return }
video.geometry?.firstMaterial?.diffuse.contents = videoScene
//Animation
guard let videoContainer = container.childNode(withName: "videocontainer", recursively: false) else { return }
videoContainer.runAction(SCNAction.sequence([SCNAction.wait(duration: 1.0), SCNAction.scale(to: 1, duration: 0.5)]))
}
}