我一直在用 ARKit 构建一个门户,虽然构建一个虚拟环境很容易创建和移动,但我想让我进入一个重复播放 360 度视频的环境。我认为可以通过将 360 度视频作为纹理包装到球体来完成,但 ARKit 似乎没有这个选项。有谁知道如何做到这一点?

我正在尝试做的一个例子可以在这里看到:
https://www.youtube.com/watch?v=xO2a7QTTAk4

最佳答案

这是一个示例,我希望这可以帮助您

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()

    // Set the scene to the view
    sceneView.scene = scene
    sceneView.isPlaying = true

    // create a texture that will be applied to sphere

    let spriteKitScene = SKScene(size: CGSize(width: sceneView.frame.width, height: sceneView.frame.height))
    spriteKitScene.scaleMode = .aspectFit

    let videoUrl  = Bundle.main.url(forResource: "360videoname", withExtension: "mp4")
    let videoPlayer = AVPlayer(url: videoUrl!)

    let videoSpriteKitNode = SKVideoNode(avPlayer:videoPlayer)
    videoSpriteKitNode.position = CGPoint(x: spriteKitScene.size.width/2, y: spriteKitScene.size.height/2)
    videoSpriteKitNode.size = spriteKitScene.size
    videoSpriteKitNode.yScale = -1.0
    videoSpriteKitNode.play()
    spriteKitScene.addChild(videoSpriteKitNode)

    // create a sphere and apply the texture
    let sphere = create(stars: SCNSphere(radius:30), and: spriteKitScene, and: nil, and: nil, and: nil, and: SCNVector3(0,0,0))

        self.sceneView.scene.rootNode.addChildNode(sphere)


}

func create(stars geometry: SCNGeometry, and diffuse: SKScene?, and specular: UIImage?, and emission: UIImage?, and normal: UIImage?, and position: SCNVector3) -> SCNNode {
    let node = SCNNode()
    node.geometry = geometry
    node.geometry?.firstMaterial?.diffuse.contents = diffuse
    node.geometry?.firstMaterial?.specular.contents = specular
    node.geometry?.firstMaterial?.normal.contents = normal
    node.geometry?.firstMaterial?.emission.contents = emission
    node.position = position
    node.geometry?.firstMaterial?.isDoubleSided = true

    return node
}

关于arkit - 如何在 ARKit 中应用 360 度视频作为纹理,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46423415/

10-11 11:15