使用场景套件无法在场景背景中看到视频

Can't see video in scene background with scene kit

我正在尝试使用 sceneKit 在我的场景背景中 运行 一个 mp4。该视频似乎是通过打印语句执行的,状态栏显示约 50 fps。但是,当应用程序在模拟器上打开时 - 我看到的只是黑屏。我可以在典型的 AVPlayer 中将视频播放到 运行,但我不知道如何将它与 Scene Kit 连接。

这是我的代码:

import UIKit
import AVKit
import SceneKit

class GameViewController: UIViewController {

var sceneView: SCNView!
//var scene: SCNScene!

var cameraNode: SCNNode!

override func viewDidLoad() {
    super.viewDidLoad()

    // Set the view's delegate
    //sceneView.delegate = self
    sceneView = self.view as! SCNView

    // Show statistics such as fps and timing information
    sceneView.showsStatistics = true

    // Create a new scene
    let scene = SCNScene()

    // 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: "master", withExtension: "mp4")!
    let player = AVPlayer(url:movieFileURL)
    scene.background.contents = player
    sceneView.play(nil) //without this line the movie was not playing

    player.play()
}


override var shouldAutorotate: Bool {
    return false
}

override var prefersStatusBarHidden: Bool {
    return true
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    if UIDevice.current.userInterfaceIdiom == .phone {
        return .allButUpsideDown
    } else {
        return .all
    }
}

}

这是我打开应用程序时看到的:

任何帮助将不胜感激,干杯!

这是 iOS 模拟器中的 运行ning,它使用 OpenGL,如统计栏中所示。在 Xcode 11 和 macOS Catalina 中,它将使用 Metal 渲染器,您应该会看到视频。

如果您 运行 在实际设备上安装该应用程序,视频也应该会出现。


sceneView.play(nil) //without this line the movie was not playing

rendersContinuously API 稍微好一点可以达到同样的效果,因为它没有隐含地引用动画。