【问题标题】:How to apply 360 video as a texture in ARKit如何在 ARKit 中应用 360 度视频作为纹理
【发布时间】:2020-07-21 19:00:30
【问题描述】:

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

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

【问题讨论】:

  • ARKit 本身不显示任何内容;它可以与 SceneKit、SpriteKit、Unity、您自己的自定义渲染引擎等一起使用——这些是在屏幕上绘制内容的部分,所以这些是要询问的部分。您使用的是哪种显示技术?
  • 我正在使用 SceneKit。我在想我可以在 SpriteKit 中创建纹理,但我不确定。

标签: arkit


【解决方案1】:

这是一个示例,希望对您有所帮助

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
}

【讨论】:

【解决方案2】:

在 iOS 11 中,如果您将 AVPlayer 分配给相应材质属性的 contents,SceneKit 可以在任何表面上显示视频。 (这没有(还没有?)出现在该属性的文档中,但在 WWDC 中提到并在标题中注明。)

如果您的视频内容正确投影(宽高比为 2:1,equirectangular or "lat/long" projection),则 360 度视频在映射到 SceneKit 球体几何体(SCNSphere,非测地线)时应正确显示。

您可能还需要设置材质的cullMode 和/或isDoubleSided 属性,以确保在将相机放置在球体内部时渲染球体的内表面。并且您应该考虑将纹理贴图分配给哪个材质属性,以便它与光照正确交互(如果您想显示无阴影的视频,emission 可能是一个不错的选择)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    • 1970-01-01
    • 2016-10-19
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多