How do I create a looping video material in SceneKit on iOS in Swift 3?

前端 未结 3 2002
甜味超标
甜味超标 2021-02-06 08:16

How do I create a material in SceneKit that plays a looping video?

3条回答
  •  伪装坚强ぢ
    2021-02-06 08:57

    It is possible to use an AVPlayer as the content of the scene's background. However, it was not working for me until I sent .play(nil) to the sceneView.

    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/ship.scn")!
    
        // create and add a camera to the scene
        let cameraNode = SCNNode()
        cameraNode.camera = SCNCamera()
        scene.rootNode.addChildNode(cameraNode)
    
        // Set the scene to the view
        sceneView.scene = scene
    
        let movieFileURL = Bundle.main.url(forResource: "example", withExtension: "mov")!
        let player = AVPlayer(url:movieFileURL)
        scene.background.contents = player
        sceneView.play(nil) //without this line the movie was not playing
    
        player.play()
    }
    

提交回复
热议问题